如何更改警报中单选按钮的文本颜色和色调?

How can I change the text color and the tint color of radiobuttons in a Alert?

现在我有一个按钮,单击它时会弹出一个带有 3 个单选按钮的 AlertDialog。

我想更改文本颜色和色调以匹配应用程序其余部分的颜色。除了对方法的调用之外,这是我为警报准备的所有代码:

public void CreateAlertDialogWithRadioButtonGroup()
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this, R.style.myDialogTheme);

        if(sharedPreferences.getString("units", "").equals("metric"))
            chosenUnit = 0;
        else if(sharedPreferences.getString("units", "").equals("imperial"))
            chosenUnit = 1;
        else
            chosenUnit = 2;

        builder.setTitle("Select the Unit for the Temperature");

        builder.setSingleChoiceItems(values, chosenUnit, new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int item)
            {
                switch(item)
                {
                    case 0://Celsius
                        unitsEditor.putString("units", "metric");
                        unitsEditor.commit();
                        break;
                    case 1://Fahrenheit
                        unitsEditor.putString("units", "imperial");
                        unitsEditor.commit();
                        break;
                    case 2://Kelvin
                        unitsEditor.putString("units", "");
                        unitsEditor.commit();
                        break;
                }
                alertDialog1.dismiss();
            }
        });
        alertDialog1 = builder.create();
        alertDialog1.show();
    }

我试图改变它们的样式,但 none 它起作用了,我似乎只能改变警报的文本颜色,而不是单选按钮。任何的想法?我没有 Alert 的布局,所以我不能为 radiogroup 做 findById。我在 Java 而不是 Kotlin 中这样做。

添加到 RadioButton XML app:buttonTint 选项如下:

<RadioButton
        android:id="@+id/radio_btn_metric"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/colorRed" />

此外,转到 color.xml 并添加您想要的颜色作为 RadioButton