Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change spinner, text and button color of material AlertDialog and ProgressDialog

Tags:

android

themes

My app extends Theme.AppCompat.Light and the material-styled dialogs appear with white background, black text color, and green buttons (spinner in ProgessDialog is also green).

I would like to change the color and font of the text, and also the color of the buttons and spinner.

How can I do it?

I found this post but the XML solution doesn't work for me and the other answers are third party libs that don't have a ProgressDialog.

Thanks!

like image 714
Ferran Maylinch Avatar asked Nov 21 '14 02:11

Ferran Maylinch


People also ask

How do I change button color in AlertDialog?

So whenever you want to change the color of AlertDialog box, just change color in styles. xml and all the dialog boxes will be updated in the whole application.

Is ProgressDialog deprecated?

This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI.

How to use ProgressDialog in Android?

In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this);

How to Create a Custom Progress dialog in Android?

Using the Custom Progress Dialog To use it, declare the class CustomProgressDialog at the beginning of your Activity: class MainActivity : AppCompatActivity() { private val progressDialog by lazy { CustomProgressDialog(this) } override fun onCreate(savedInstanceState: Bundle?) { super.


1 Answers

To have the whole "Material Experience" you should use the latest AppCompat everywhere. Instead of android.app.AlertDialog use android.support.v7.app.AlertDialog to target devices < 21.

It is enough just to set your AppTheme up correctly like in the following:

<style name="AppTheme" parent="Base.AppTheme">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>

    <!-- This is the interesting part -->
    <item name="android:dialogTheme">@style/AppTheme.Dialog</item>
    <item name="dialogTheme">@style/AppTheme.Dialog</item>
    <item name="android:alertDialogTheme">@style/AppTheme.Dialog</item>
    <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<!-- Style the dialog like the normal AppTheme -->
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>
like image 79
David Medenjak Avatar answered Oct 19 '22 16:10

David Medenjak