Can you help my figure out why is my alert dialog BLACK?!
Recently i changed my app theme to support material design, but my alert dialog got black!
Here is my create dialog Code:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(TestActivity.this);
alertDialog.setCancelable(true);
alertDialog.setTitle("sample");
alertDialog.setItems(new String[] { "a", "b" }, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertDialog.show();
and its my main style and dialog style
<style name="MaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:alertDialogStyle">@style/AppDialog</item>
<item name="android:alertDialogTheme">@style/AppDialog</item>
<item name="android:textColor">@color/black</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:dialogTheme">@style/AppDialog</item>
<item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
<item name="android:textColorHint">@color/gray_1</item>
<item name="colorAccent">@color/myAccentColor</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowBackground">@color/black</item>
</style>
<style name="AppDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFC107</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#4CAF50</item>
</style>
You don't set theme for AlertDialog, for using theme, change code to:
ContextThemeWrapper ctw = new ContextThemeWrapper(TestActivity.this, R.style.AppDialog);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctw);
您必须在alertdialog构建器中使用light主题,例如THEME_HOLO_LIGHT。
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.