Java 如何更改警报中单选按钮的文本颜色和色调?
现在我有一个按钮,点击它会弹出一个带有3个单选按钮的AlertDialog 我想更改文本颜色和色调,以匹配应用程序其余部分的颜色。除了对方法的调用之外,这是我对警报的所有代码:Java 如何更改警报中单选按钮的文本颜色和色调?,java,android-studio,radio-button,android-alertdialog,Java,Android Studio,Radio Button,Android Alertdialog,现在我有一个按钮,点击它会弹出一个带有3个单选按钮的AlertDialog 我想更改文本颜色和色调,以匹配应用程序其余部分的颜色。除了对方法的调用之外,这是我对警报的所有代码: public void CreateAlertDialogWithRadioButtonGroup() { AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this, R.style.myDialogTheme);
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();
}
我尝试过在样式上更改它们,但都不起作用,我似乎只能更改警报的文本颜色,而不能更改单选按钮。有什么想法吗?我没有警报的布局,因此无法为radiogroup执行findById。我是用Java而不是Kotlin来做这件事的。将app:buttonit选项添加到RadioButtonXML中,如下所示:
<RadioButton
android:id="@+id/radio_btn_metric"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/colorRed" />
另外,转到color.xml并添加您想要成为单选按钮的颜色,该按钮将不起作用,因为我没有为警报使用单独的布局。您可以在myDialogTheme中更改style.xml中的主色和强调色。