I used the following line in my manifest:
android:theme="@android:style/Theme.Light.NoTitleBar"
to have no title bar and display the light version of AlertDialog in my app, like in example:
But it's displaying in dark theme still:
My Dialog Java code:
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 do I keep the theme light for AlertDialog?
The top dialog in your post is a Holo Light themed dialog whereas the bottom one is the older themed dialog. You cannot get a Holo Light themed dialog on versions below Honeycomb. Here is a little snippet I use to select the light theme based on what android version the device is running.
The AlertDialog.Builder
will use the theme of the context it's passed. You can use a 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With