What's the default v7 compat theme for AlertDialog - android

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>

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()

AlertDialog custom EditText view and copy-paste menu

I'm using the AlertDialog inside a DialogFragment from appCompat 22.2.1 to make something like the following.
But as you can tell the copy-paste menu features are pretty messed up. What can I do to bring the copy-paste menu bar from the background to the foreground? And Also how can I change the "PASTE" Label color?
This is my xml Style for the dialog
<style name="MyDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">#color/blue_500</item>
<item name="colorControlNormal">#color/blue_500</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#color/grey_200</item>
<!-- Used for the background -->
<item name="android:background">#color/dark_gray</item>
</style>
And My dialog code inside The DialogFragment
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final AlertDialog.Builder alertCompat = new AlertDialog.Builder(getActivity(), R.style.MyDialogStyle);
alertCompat.setTitle("Hello wtf");
alertCompat.setView(R.layout.add_mac_dialog_frag);
alertCompat.setPositiveButton(R.string.ok, this);
alertCompat.setNegativeButton(R.string.cancel, this);
return alertCompat.create();
Any Ideas?
This appears to be the AppCompat problem documented by AOSP Issue 170105. The fix will be in the M release (v23) of AppCompat.
OK since this is a known bug and the appCompat devs love to break a little something every time and then take forever to release new fixes, I ended up using the amazing material dialogs library

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

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;);

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