user3231871
user3231871

Reputation: 191

AlertDialog style and color

I am trying to create alert dialog to look like this

enter image description here

But I can't figure out why, when I launch app on my device I get dialog looking like this:enter image description here

I followed many tutorials and still got alert dialog looking like that. Code is pretty standard so I am not gonna post it, but if required I will. My device is running on 4.3 android. My question: Does alert style change with device API Lvl? If so what can I do to create Dialog like on first pic? I would create custom dialog with layout inflater, but I want to have those cool buttons.

Upvotes: 1

Views: 671

Answers (2)

bmat
bmat

Reputation: 2153

The issue is with Themes.

The Dialog from the first screenshot uses the "Holo Light" theme, while the second one uses the "Theme" theme.

You have two options for creating an AlertDialog like the one in the first picture.

  1. You can change the theme for your application or activity to inherit from Holo.Light (see Android's Styles & Themes guide). This will change the appearance of AlertDialogs across the entire application or activity.

  2. You can set the theme for an individual AlertDialog in the following manner:

new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog)) .setTitle("Demo Dialog") .setMessage("This AlertDialog uses the theme android.R.style.Theme_Holo_Light_Dialog.") .create() .show();

Either of these options will produce the following result:

AlertDialog with Holo Light theme

Upvotes: 3

Arun Kumar
Arun Kumar

Reputation: 2934

You should create custom dialog box in android.

http://www.mkyong.com/android/android-custom-dialog-example/

Upvotes: 0

Related Questions