Right now I have a button and when clicked it pops up with an AlertDialog with 3 radiobuttons.
I want to change the text color and the tint color to match what I have on the rest of the app. Besides the call to the method this is all the code I have for the Alert:
JavaScript
x
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();
}
I have tried to change them in the style but none of it works, I can only seem to change the textcolor of the alert and not the radiobuttons. Any idea? I do not have a layout for the Alert so I can’t do a findById for the radiogroup. I am doing this in Java and not Kotlin.
Advertisement
Answer
Add to RadioButton XML the app:buttonTint option as follows:
JavaScript
<RadioButton
android:id="@+id/radio_btn_metric"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/colorRed" />
Also, go to color.xml and add the color you want to be the RadioButton