gpt4 book ai didi

android.view.InflateException - 膨胀类 android.widget.EditText 时出错

转载 作者:行者123 更新时间:2023-11-30 03:29:08 25 4
gpt4 key购买 nike

您好,我正在尝试在屏幕上显示自定义的 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();

}

如何显示 AlertDialog

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

最佳答案

替换

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

android:textAppearance="@android:style/TextAppearance.Large"

关于android.view.InflateException - 膨胀类 android.widget.EditText 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17782825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com