私はユーザーが製品を見たり評価したりできるアプリを開発中です。だから、私がratingButton
をクリックするたびに、私はポップアップかAlertDialogを得て、私は1から5の星を評価することができます。ユーザーは評価を保存またはキャンセルする必要があります。しかし、RatingBarはAlertDialogの中に表示されていないようです。下の画像は、ダイアログに星印を表示する必要があります。 RatingBarをAlertDialogに表示させるにはどうしたらいいですか?AlertDialogの中にRatingBarが表示されない
これは私がこれまで持っているものです。 ratingBtn
ratingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogStyle);
builder .setTitle("Rate!");
View rootView = inflater.inflate(rate_layout, container, false);
final RatingBar ratingBar = (RatingBar) rootView.findViewById(R.id.ratingBar);
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
String value = String.valueOf(ratingBar.getRating()*2);
Toast.makeText(activity, " " + value, Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(activity, "Saved", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.getWindow().setLayout(600, 400);
alert.show();
}
});
rate_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.Rate">
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rateMessage"
android:layout_centerHorizontal="true"
android:layout_marginBottom="52dp"
android:theme="@style/RatingBar"/>
</RelativeLayout>
のstyles.xml
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#626262</item>
<item name="android:textColorPrimary">#616161</item>
<item name="android:background">@color/white</item>
</style>
をこの行を追加します。 –