這裏我爲創建對話框代碼,如何更改按鈕的顏色在警報對話框
builder.setMessage(msg).setNeutralButton("Dismiss",dialogClickListener).setPositiveButton("Edit", dialogClickListener)
.setNegativeButton("Delete", dialogClickListener).show();
是否有可能顯示駁回藍色,而不是紅色的?
這裏我爲創建對話框代碼,如何更改按鈕的顏色在警報對話框
builder.setMessage(msg).setNeutralButton("Dismiss",dialogClickListener).setPositiveButton("Edit", dialogClickListener)
.setNegativeButton("Delete", dialogClickListener).show();
是否有可能顯示駁回藍色,而不是紅色的?
首先,從生成器來創建AlertDialog:
AlertDialog dialog = builder.create();
然後你就可以找到您的按鈕和更改顏色:
dialog.show(); //Only after .show() was called
dialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(your_color);
dialog.getButton(dialog.BUTTON_NEUTRAL).setTextColor(your_color);
這裏您使用下一個method:
void setTextColor (int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
Parameters
color int: A color value in the form 0xAARRGGBB. Do not pass a resource ID. To get a color value from a resource ID, call getColor.
謝謝你,一個有點神祕的答案,但它指出我正確的方向,現在它的作品。 – alberto
啊這是可能的,顏色從風格改變,你可以自定義樣式您的對話框如下圖所示:
<style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">yourColorCode</item>
<item name="android:colorAccent">yourColorCode</item>
</style>
試試這個https://stackoverflow.com/questions/39930505/change-color-of-button-in-alertdialog-builder –
的[在AlertDialog.Builder按鈕改變顏色]可能的複製( https://stackoverflow.com/questions/39930505/change-color-of-button-in-alertdialog-builder) –
Sheikh給出的答案告訴我AlertDialog dialog = builder.create(); Brahmy adigopula在原始問題中的回答僅僅是指AlertDialog.show出於藍色 – alberto