How to show a Holo (dark) AlertDialog in a themed activity? - android

I have tried to use a content wrapper:
ContextThemeWrapper wrapper = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Dialog);
AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);
The result of this, is a dialog box of a mix of both dark and white, horrible.
I have also tried using customized styles and etc in the past 2 hours, no luck. I believe the solution must be very simple, I just need to trick the AlertDialog Builder to think my activity is Holo dark themed. But how?
This is how I themed my activity, maybe I did something wrong there:
<style name="ThemeSolarizedLight" parent="android:Theme.Holo.Light">
<item name="android:background">#color/light_yellow</item>
<item name="android:textColor">that No Wi-fi color you see up there</item>
</style>

You are using the actionbar's theme instead use the theme made for dialog
sample:
ContextThemeWrapper wrapper = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Dialog;);

Related

what theme to use for the AlertDialog to adjust the color automatically with day/night theme

if the app called AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); it is expect to show dark theme, and if not the app is with light theme.
Having AlertDialog.Builder(this), and would like to apply one theme so that in MODE_NIGHT it shows the dialog with dark theme, other wise the dialog shows with the light theme, something like below (but this android.R.style.Theme_Material_Dialog will causes the dialog to be always in dark theme)
AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog)
Is there one theme for the AlertDialog? or it has to define two themes and check the mode and then to code with the theme respectively?
Define your alert dialog in styles.xml
<style name="MyDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert"/>
In your code
AlertDialog.Builder(this, R.style.MyDialogStyle)
And give it a try!
add to your theme style:
<item name="alertDialogTheme">#style/Theme.AppCompat.DayNight.Dialog.Alert</item>
<item name="android:alertDialogTheme">#style/Theme.AppCompat.DayNight.Dialog.Alert</item>
use the dialog from appcompat
import androidx.appcompat.app.AlertDialog;
AlertDialog alertDialog = new AlertDialog.Builder(context).create()

What's the default v7 compat theme for AlertDialog

In my app I use the Theme.AppCompat.Light.DarkActionBar as the base for my apps.
When I create a AlertDialog I'm using creating it without a specific theme.
Now I like to update some colors in the dialog, but I not know what's the theme that I need to use as a parent for the AlertDialog.
I have tried Theme.Holo.Dialog and Theme.AppCompat.Light.Dialog but aren't.
Thanks
Try parent="#android:style/Theme.Dialog"
I auto answer the question...
This si the default Dialog theme for v7 compat light theme (it needs to update the Dialog width (I don't know for what reason).
#android:dimen/dialog_min_width_major
#android:dimen/dialog_min_width_minor
the support library (sadly) doesn't have dialogs themes, at least not yet.
However, there are some third party libraries that allow you to have material design dialogs, such as AlertDailogPro
With the new AppCompat v22.1 you can use the new android.support.v7.app.AlertDialog.
Just use a code like this (of course in your case you have to use a custom layout to have the progress bar)
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Dialog");
builder.setMessage("Lorem ipsum dolor ....");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
And use a style like this:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#5fa3d0</item>
</style>

AlertDialog Styling Issues

I'm trying to change the style of an AlertDialog by using the following code :
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogTheme));
In my styles.xml, I have this style:
<style name="AlertDialogTheme" parent="#android:style/Theme.Holo.Dialog">
<item name="#android:background">#9933CC</item>
<item name="#android:textColor">#FAF5F7</item>
<item name="#android:textSize">5sp</item>
</style>
So basically the issues are :
1.- There is a overhead of the background, not limiting it by the AlertDialog frame.
2.- The color of the buttons are not being affected at all.
3.- The textSize does not affect either.
I had similar problems once with a ProgressDialog, it wasn't using the context I passed through the ContextThemeWrapper. It should work if you pass the context and the style separately through the constructor:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);

Android override Theme.Dialog windowTitleStyle property for AlertDialog.Builder

I'm using AlertDialog.Builder like this:
ContextThemeWrapper cw = new ContextThemeWrapper(context, R.style.AlertDialogTheme);
AlertDialog.Builder builder = new AlertDialog.Builder(cw);
This is my custom AlertDialogTheme style:
<style name="AlertDialogTheme" parent="#android:Theme.Dialog">
<item name="android:textSize">15sp</item>
<item name="android:windowTitleStyle">#style/custom_style</item>
</style>
The textSize attribute works fine for the list of items I put in the builder with builder.setItems(), but it doesn't work on the title, so I've tried to override the windowTitleStyle attribute, but it doesn't work.
Is it even possible or am I doing something wrong?
I'm having similar issues, and I've done just what you have. One thing to note is that windowTitleStyle isn't used in the dialog title before API 14. Before that it was textAppearanceMedium. And in the default (pre-holo) dialog it is textAppearanceLarge.
Unfortunately, I'm setting all three of these to my custom style and testing in KK, but it still doesn't update the color as I'm expecting.

Android Holo Dialog has 2 backgrounds layered on top of one another

The dialog looks like this. There is a layer behind the dialog itself about 10-20 pixels or so on each side. The theme I am using is Theme.Holo.Dialog
I tried creating a custom dialog with a transparent background, but that did not work:
<style name="CustomHoloDialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:background">#android:color/transparent</item>
</style>
Does anyone have any ideas on this?
If you want to style a Dialog then you have to use a ContextThemeWrapper:
AlertDialog.Builder mBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Dialog));

Categories

Resources