1

我已经设置了我的自定义 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 或其他活动上工作,如下所示: 有用

但在我的对话框中它没有,并且已经尝试上传到我的设备,但仍然没有.. 它不起作用

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

4

1 回答 1

1

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

于 2013-08-08T09:51:48.717 回答