1

您好,我正在尝试在屏幕上显示自定义 AlertDialog。我在对话框中添加了一个布局,这个布局包括两个 TextView、一个 RatingBar 和一个 EditText。

当我尝试弹出对话框时,我收到了这个异常:

E/AndroidRuntime(12989): android.view.InflateException: Binary XML file line #25: Error inflating class android.widget.EditText

重要的一点是此错误发生在 Android 2.3.x 设备上,它在 Android 4.x 上运行良好

dialog_comment.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RatingBar
        android:id="@+id/DialogCommentRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:stepSize="1" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/DialogCommentRatingBar"
        android:text="Yorumunuz"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/DialogCommentComment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:background="?android:attr/editTextBackground"
        android:ems="10"
        android:gravity="top"
        android:inputType="textMultiLine" >
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Oyunuz"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

评论对话框.java

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater inflater=getActivity().getLayoutInflater();
        final View view=inflater.inflate(R.layout.dialog_comment, null);

        final RatingBar rating=(RatingBar)view.findViewById(R.id.DialogCommentRatingBar);
        final EditText comment=(EditText)view.findViewById(R.id.DialogCommentComment);      

        AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());

        builder.setView(view);

        builder.setTitle("Enter Your Comment!");
        return builder.create();

    }

如何显示警报对话框

        FragmentManager fm = getSupportFragmentManager();
        CommentDialog commentDialog = new CommentDialog();
        commentDialog.show(fm, "fragment_comment_dialog");
4

2 回答 2

1

代替

android:textAppearance="?android:attr/textAppearanceLarge"

android:textAppearance="@android:style/TextAppearance.Large"
于 2013-07-22T08:38:49.393 回答
0

删除了我的 EditView(纯文本文本字段),将另一个放入 content_....xml 并且这次没有更改任何样式。一切都以 EditView 上的默认样式正确运行。

于 2016-02-16T23:49:04.017 回答