2016-12-08 56 views
0

如何更改單選按鈕的顏色?下圖顯示默認情況下單選按鈕是藍色的,但我想改變它。如何更改單選警報對話框的顏色?

enter image description here

我的代碼是:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        context); 
      alertDialogBuilder.setCustomTitle(promptsView); 
      alertDialogBuilder.setItems(frequencyName, null); 
      // alertDialogBuilder.setTitle("SELECT FREQUENCY"); 


      alertDialogBuilder.setSingleChoiceItems(frequencyName, -1, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialogInterface, int i) { 

        selectedFre = frequencyName[i]; 
       } 
      }); 

      alertDialogBuilder 
        .setCancelable(false) 
        .setPositiveButton("OK", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, int id) { 

            txtFrequency.setText(selectedFre); 
           } 
          }) 
        .setNegativeButton("Cancel", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, int id) { 
            dialog.cancel(); 
           } 
          }); 


      AlertDialog alertDialog = alertDialogBuilder.create(); 


      alertDialog.show(); 
+2

重複的:http://stackoverflow.com/questions/23255776/android-alert-dialog-replace-default-blue-with-another-color –

+0

Thanks..can你告訴我什麼是參數他們正在傳遞這個方法res.getIdentifier(「titleDivider」,「id」,「android」); –

+0

請看:https://developer.android.com/reference/android/content/res/Resources.html#getIdentifier(java.lang.String,java.lang.String,java.lang.String)。基本上這是說:從包「安卓」 –

回答

1

使用該樣式像下面的例子爲AlertDialog

<style name="MaterialThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="colorAccent">@color/action_bar_background</item> 
</style> 

創建AlertDialog.Builder創建相應的樣式。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
      getActivity(), 
      R.style.MaterialThemeDialog); 
    alertDialogBuilder.setTitle(R.string.image_resolution); 
    alertDialogBuilder.setSingleChoiceItems(R.array.quality_labels, getPosition(), this); 

    AlertDialog alertDialog = alertDialogBuilder.create(); 
    alertDialog.show(); 
+0

得到「titleDivider」的ID感謝很多傢伙..它的工作對我來說..我已upvoted爲你..再次感謝.. –

+0

歡迎。如果這是你的問題的解決方案,也接受我的答案。 –

相關問題