If you use an AlertDialogBuilder you can set the style XML resource for the dialog. Then you can use a LayoutInflator to inflate your custom view and call setView on the builder
Custom RatingBar doesn't work on Dialog
-
23-06-2022 - |
سؤال
I have set my custom RatingBar Style
Inside style.xml this is my code:
<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>
now I have created a custom layout for a Dialog (Xml) [is inside a 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" />
and on my class I have this code:
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();
}
Now my RatingBar works fine everywhere, but on this dialog it doesn't work and I have no idea why..
Please help me
EDIT I don't know why it doesn't work on emulator but on preview in IDE totally works!
EDIT2 So this is my result:
How you can see my custom RatingBar works on Listview or On other activity like this:
but on my dialog it doesn't, and already tried to upload to my device, but still nothing..
Sorry for "blur" but can't show (working in a office) my wip app..
المحلول
لا تنتمي إلى StackOverflow