Android override Theme.Dialog windowTitleStyle property for AlertDialog.Builder - android

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.

Related

Styling custom dialog fragment not working

I'm trying to style all my dialog fragments to look the same in my app. The dialogs coming from my settings fragment are styled exactly the way I want it. For my custom dialog fragments, the style is similar but not exactly the same. For some reason the spinner, timepicker, datepicker, radiobuttons, and edittext widgets inside my custom dialog fragments don't pick up the same style. In fact, the widgets blend in with the white background and you can't see that they are there. What am I doing wrong?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
<style name="Theme.Base" parent="AppTheme">
<item name="colorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorPrimaryDark">#color/SecondaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
<item name="android:textColorPrimary">#color/PrimaryTextColor</item>
<item name="android:alertDialogTheme">#style/AppTheme.DialogStyle</item>
</style>
<style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
</style>
I'm applying the theme to my custom dialog fragment like this:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_DialogStyle);
My settings dialog looks like this (Exactly how I want it):
Settings Dialog Fragment
My custom dialog fragment looks like this:
Custom Dialog Fragment
As you can see, the radio button selected color red and you can't see the unselected radio button.
Finally got an answer!!!
It's an issue or bug with AppCompat 22+.
Check out link here
Apparently this was a bug with fragments and widgets weren't getting the material themed in a fragment. It seems they fixed this issue, but the issue still holds in a dialog fragment based on what I'm going through.
The problem comes when you use the inflater instance passed to Fragment#onCreateView(). The workaround for now is to instead used the LayoutInflater from getActivity().getLayoutInflater() according to google.
So I changed my code to:
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog, null);
from:
View view = LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.dialoge, null);
All my widgets are now themed. Thanks everyone. Hopes this helps someone else.
I believe you need to set the theme on the actual Dialog and not the Fragment
Use this constructor to create your AlertDialog:
AlertDialog.Builder(Context context, int theme)
ie
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), theme)
I think you need to add one more item in style of your dialog. android:textColorSecondary will show color of un selected checkbox.
in your style add it.
</style>
<style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
<item name="android:textColorSecondary">#000000</item>
</style>
It will make un Checked checkbox or toggle button edge color black. you need to change #000000 to color your want to show.
See if this helps -
Android appcompat-v7:21.0.0 change material checkbox colors
In short, try setting android:textColorSecondary.

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

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 alertdialog theme

iv tried several diffrent ways but cant seem to get the alertdialog to properly change themes. my activities have there custom theme set in the manifest so im not sure if this is causing the conflict.
im using :
AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(this,R.style.DialogStyle)).create();
and im using the follwing style:
<style name="DialogStyle" parent="android:Theme" >
<item name="android:windowBackground">#drawable/background2</item>
<item name="android:textColor">#014076</item>
</style>
it only changes certain text colours. all the titles and messages are all still default white colours and the background doesnt change either.
any help please.
Prior to gingerbread, 2.3.X, you can't.
It explicitly sets the theme in the constructor of the dialog, but in gingerbread you can supply it.

Categories

Resources