Show Light AlertDialog with Theme.Light.NoTitleBar

In the manifest, I used the following line:

android:theme="@android:style/Theme.Light.NoTitleBar" 

do not have a title and display the light version of AlertDialog in my application, as in the example: enter image description here

But it appears in a dark topic:

enter image description here

My Java code is:

  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(); 

How to save theme highlighting for AlertDialog?

+7
java android android-alertdialog
source share
3 answers

The top dialog in your post is the Holo Light dialog, while the bottom is an older topic dialog. You cannot get the Holo Light theme dialogue on versions below Honeycomb. Here is a small snippet that I use to select a light theme based on the version of Android the device is running on.

AlertDialog.Builder will use the theme of the passed context. You can use ContextThemeWrapper to set this.

 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); 
+26
source share

You can use something like this when creating an 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. 

This code will create the Holo Styled AlertDialog in newer versions and a regular AlertDialog-based device on devices with an older version of Android.

+13
source share

You must use AlertDialog Builder . With it, you can set the style for your dialogue. See the following example: http://pastebin.com/07wyX0V3

 <style name="popup_theme" parent="@android:style/Theme.Light"> <item name="android:windowBackground">@color/back_color</item> <item name="android:colorBackground">@color/back_color</item> </style> 
+3
source share

All Articles