![](/img/trans.png)
[英]How can i change the text color on textview with with a specific text?
[英]How can I change the text color and the tint color of radiobuttons in a Alert?
現在我有一個按鈕,點擊它會彈出一個帶有 3 個單選按鈕的 AlertDialog。
我想更改文本顏色和色調顏色以匹配我在應用程序的 rest 上的顏色。 除了對方法的調用之外,這是我為警報所擁有的所有代碼:
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();
}
我試圖改變它們的風格,但都不起作用,我似乎只能改變警報的文本顏色而不是單選按鈕。 任何想法? 我沒有警報的布局,所以我不能為無線電組做 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" />
此外, go 到 color.xml 並添加您想要的顏色作為 RadioButton
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.