javaandroidstylesapp-themes

Custom Alert Style with Multiple Theme


I am confused while using custom alert dialogue styles in my application, due to there being multiple themes in my application. I have three themes in my application, called themeGrey, themeTeal and themePink. I have an alert dialogue style like below

style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">

        <item name="android:textColorPrimary">@color/colorAccent</item>
        <item name="android:textColor">@color/colorAccent</item>
        <item name="android:background">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="textColorAlertDialogListItem">@color/colorAccent</item>
        <item name="android:textColorSecondary">@color/colorAccent</item>

    </style>

I have used it in my app like below

mProgress = new ProgressDialog((this), R.style.AlertDialogTheme);

Now my question is, how can I define a different style for each theme? I do not want apply with a conditional. Can I do it by declaring a theme as an item? Thanks


Solution

  • I have solved removing style from java code like below

    mProgress = new ProgressDialog((this));
    

    and delcared alert style in theme like below

    <item name="android:alertDialogTheme">@style/AlertDialogThemeTeal</item>
    

    Thanks