[英]How to change the Android AlertDialog selection background color
我在android中使用“警報對話框”,我需要在更改顏色的同時選擇我該怎么做?
如果您檢查圖像第二行“右”被選中但不正確可見,所以我想將其更改為較深的顏色。
android.app.AlertDialog.Builder builderSingle = new android.app.AlertDialog.Builder(ModeActivity.this);
builderSingle.setTitle("Select Part");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
ABIModeActivity.this,
android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("1");
arrayAdapter.add("2");
arrayAdapter.add("3");
如果要更改background
色,請嘗試:
AlertDialog dialog = builder.create();
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
希望這可以幫助
嘗試這個:
AlertDialog.Builder builderSingle = new AlertDialog.Builder(ModeActivity.this, R.style.Your_App_theme);
並在style.xml中添加主題:
<style name="Your_App_theme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorControlNormal">@color/colorPrimary</item>
<item name="colorControlActivated">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
參見下面的樣式代碼:
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@color/myColor</item>
</style>
現在,此樣式適用於對話框:
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.