Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 分级栏未在AlertDialog内显示_Android_Xml_Android Alertdialog_Ratingbar - Fatal编程技术网

Android 分级栏未在AlertDialog内显示

Android 分级栏未在AlertDialog内显示,android,xml,android-alertdialog,ratingbar,Android,Xml,Android Alertdialog,Ratingbar,我正在开发一个用户可以查看和评价产品的应用程序。因此,每当我点击评级按钮时,就会出现一个弹出窗口或警报对话框,我可以在其中评级1-5星。然后用户应该保存或取消评级。但是,分级栏似乎没有显示在AlertDialog内。下面的图像应该在对话框上显示星星。如何使分级栏显示在AlertDialog中 这就是我到目前为止得到的 用于分级BTN的OnClick侦听器 ratingBtn.setOnClickListener(new View.OnClickListener() { @Ov

我正在开发一个用户可以查看和评价产品的应用程序。因此,每当我点击
评级按钮
时,就会出现一个弹出窗口或警报对话框,我可以在其中评级1-5星。然后用户应该保存或取消评级。但是,分级栏似乎没有显示在AlertDialog内。下面的图像应该在对话框上显示星星。如何使分级栏显示在AlertDialog中

这就是我到目前为止得到的

用于分级BTN的OnClick侦听器

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>

#626262
#616161
@颜色/白色

为什么要对分级栏使用警报对话框。您只需使用以下命令: ratingBar=(ratingBar)findViewById(R.id.ratingBar); txtRatingValue=(TextView)findViewById(R.id.txtRatingValue)


然后您必须使用自定义警报对话框。

您错过了
builder.setView(rootView)

在这一行之后加上这一行

View rootView = inflater.inflate(rate_layout, container, false);

我想要alertdialog中的ratingBar
View rootView = inflater.inflate(rate_layout, container, false);