android - 自定义 RatingBar 不适用于 Dialog

标签 android android-custom-view android-dialog ratingbar

我已经设置了自定义 RatingBar 样式

在 style.xml 中,这是我的代码:

<item name="android:ratingBarStyle">@style/RatingBarStyle</item>
<style name="RatingBarStyle" parent="android:Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/ratingbar</item>
    <item name="android:minHeight">13dip</item>
    <item name="android:maxHeight">13dip</item>
</style>

现在我已经为 Dialog (Xml) 创建了自定义布局 [在 relativelayout 中]:

<RatingBar
    android:id="@+id/custom_dialog_vota_ratingbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/custom_dialog_vota_label_ratingbar"
    android:layout_below="@+id/custom_dialog_vota_label_ratingbar"
    android:layout_marginTop="2dp"
    android:max="5"
    android:numStars="5"
    android:stepSize="0.5" />

在我的课上我有这段代码:

public void onClick(View view) {
            final Dialog dialog = new Dialog(mContext);
            dialog.setContentView(R.layout.custom_dialog_vota);
            dialog.setTitle("Vota");
            String t = ((TextView)dialog.findViewById(R.id.custom_dialog_vota_label_ratingbar)).getText().toString();
            ((TextView)dialog.findViewById(R.id.custom_dialog_vota_label_ratingbar)).setText(t + nome_book);
            dialog.show();
        }

现在我的 RatingBar 在任何地方都可以正常工作,但是在这个对话框中它不起作用,我不知道为什么..
请帮助我

编辑 我不知道为什么它在模拟器上不起作用,但在 IDE 中预览完全可以!

EDIT2 所以这是我的结果:
如何查看我的自定义 RatingBar 在 Listview 或其他 Activity 上的工作情况,如下所示: it works

但在我的对话框中它没有,并且已经尝试上传到我的设备,但仍然没有.. it doesn't work

抱歉“模糊”但无法显示(在办公室工作)我的 wip 应用..

最佳答案

如果您使用 AlertDialogBu​​ilder,您可以为对话框设置样式 XML 资源。然后你可以使用 LayoutInflator 来膨胀你的自定义 View 并在构建器上调用 setView

关于android - 自定义 RatingBar 不适用于 Dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18105409/

相关文章:

android - 许多 Android 对话框的一个监听器

Android 传感器读数不返回所有传感器

android - Android的Parcelable中的in.readInt()是否等于(Integer)in.readValue(Integer.class.getClassLoader())?

android - 将 XML 中的所有 subview 添加到 ViewGroup 后回调?

android - android 上的自定义 editText

android - 无论我尝试什么,AlertDialog 都不会包装内容

android - BottomSheetDialogFragment 不断出现在 onResume

android - 是否可以在不同的 fragment 中为 float 操作按钮设置不同的操作?

在自定义 View 按钮中实现 OnClickListener 时,XML 的 Android onclick 不起作用

android - 如何在 Android 上显示警报对话框?