我在清单中使用了以下行:
android:theme="@android:style/Theme.Light.NoTitleBar"
没有标题栏并在我的应用程序中显示AlertDialog的简易版本,例如:
但它仍以黑暗主题展示:
我的Dialog Java代码:
new AlertDialog.Builder(FreeDraw.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Clear Drawing?") .setMessage("Do you want to clear the drawing board?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); startActivity(getIntent()); } }) .setNegativeButton("No", null) .show();
如何保持AlertDialog的主题灯?
帖子中的顶部对话框是Holo Light主题对话框,而底部对话框是较旧的主题对话框.你不能在Honeycomb下面的版本上获得Holo Light主题对话框.这是我用来根据设备运行的android版本选择灯光主题的小片段.
该AlertDialog.Builder
会用它传递的上下文的主题.您可以使用a ContextThemeWrapper
来设置它.
ContextThemeWrapper themedContext; if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) { themedContext = new ContextThemeWrapper( FreeDraw.this, android.R.style.Theme_Holo_Light_Dialog_NoActionBar ); } else { themedContext = new ContextThemeWrapper( FreeDraw.this, android.R.style.Theme_Light_NoTitleBar ); } AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
您可以在创建时使用以下内容AlertDialog
:
AlertDialog.Builder builder = null; if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { builder = new AlertDialog.Builder(BaseActivity.this); } else { builder = new AlertDialog.Builder(BaseActivity.this, AlertDialog.THEME_HOLO_LIGHT); } // ... do your other stuff.
此代码将在较新版本中创建Holo Styled AlertDialog,在具有旧版Android的设备上创建基于普通设备的AlertDialog.