Android - change the dialog title style for all dialogs in the application

Is there a way to change all warning dialogs that appear in an Android app? I also want to change the dialogs that are also generated by the system (for example, the "Edit Text" dialog box that opens when you click on any EditText for a long time). I want to change the font color of the title and the size of all the dialogs in my application.

Is there any way to do this?

I tried installing android:alertDialogTheme in my theme. But it doesn't seem to work. The following code is

 <style name="Theme.DLight" parent="android:Theme.Light.NoTitleBar"> <item name="android:alertDialogTheme">@style/DialogStyle</item> </style> 

and

 <style name="DialogStyle" parent="android:Theme" > <item name="android:windowBackground">@drawable/background_holo_light</item> <item name="android:textColor">#014076</item> </style> 

EDIT

I do not call a dialog from my code. This is only the default dialog box that appears when you long click on any EditText. Typically, this contains keyboard options such as the Select word, Select all, Input method, etc.

+8
android android-alertdialog android-theme
source share
3 answers

In your topic of dialogue, the attribute you need to change windowTitleStyle . There, specify a style for your title and determine the appearance of the text for this title. For example, to display the heading red and bold:

 <style name="DialogStyle" parent="android:Theme"> ... <item name="android:windowTitleStyle">@style/DialogWindowTitle_Custom</item> </style> <style name="DialogWindowTitle_Custom" parent="@style/DialogWindowTitle_Holo"> <item name="android:maxLines">1</item> <item name="android:scrollHorizontally">true</item> <item name="android:textAppearance">@style/TextAppearance_DialogWindowTitle</item> </style> <style name="TextAppearance_DialogWindowTitle" parent="@android:style/TextAppearance.Holo.DialogWindowTitle"> <item name="android:textColor">@android:color/holo_red_light</item> <item name="android:textStyle">bold</item> </style> 

If you want to style your AlertDialog a bit, I wrote a blog post detailing the steps.

+10
source share
 import android.app.ProgressDialog; import android.content.Context; import android.view.animation.Animation; public class MyProgressDialog extends ProgressDialog { public MyProgressDialog(Context context) { super(context,R.style.NewDialog); // TODO Auto-generated constructor stub } } 

// RESOURCE STYLE FILE res-> values-> mydialog.xml

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="NewDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTitleStyle">@null</item> <item name="android:colorBackground">#ffffff</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:width">30dip</item> <item name="android:height">30dip</item> <item name="android:textColor">#FF0000</item> </style> </resources> 

// AND USE THIS CODE AT ANY TIME IN YOUR APPLICATION TO GET THE CUSTOM PROGRESS DIALOG

 MyProgressDialog pd = new MyProgressDialog(YouActivity.this); pd.setMessage("Loading. Please wait..."); pd.show(); 

Thanks:)

+1
source share

In styles.xml:

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> //All your other styles and add the one mntioned below. <item name="alertDialogTheme">@style/AlertDialogStyle</item> </style> 

In the AlertDialog styles add:

  <style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">@color/colorAccent</item> <item name="android:textColorPrimary">@color/primary_text</item> <item name="android:editTextColor">@color/primary_text</item> <item name="android:background">@color/white</item> <item name="android:windowTitleStyle">@style/TextAppearance.AppCompat.Title</item> </style> 

windowTitleStyle is important to add, as it will give your title the effect you need.

Now just use this theme in your AlertDialog for any action you want, as shown below:

  AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.AlertDialogStyle); 
0
source share

All Articles