我已经设置了自定义 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 上的工作情况,如下所示:
但在我的对话框中它没有,并且已经尝试上传到我的设备,但仍然没有..
抱歉“模糊”但无法显示(在办公室工作)我的 wip 应用..
最佳答案
如果您使用 AlertDialogBuilder,您可以为对话框设置样式 XML 资源。然后你可以使用 LayoutInflator 来膨胀你的自定义 View 并在构建器上调用 setView
关于android - 自定义 RatingBar 不适用于 Dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18105409/