I have created custom style for checkbox
<style name="CheckBoxtpi" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/tpi_btn_check_holo_light</item>
</style>
And apply it to my Theme, it works pretty, but all checkboxes in alert dialogs still standart Holo Blue color.
How can i change this?
There are two alternatives you can do;
Change your context from getApplicationContext() or any other to explicitly MyActivity.this, (whatever your activity name is) when you build your dialog.
This will probably solve the problem.
You may create a custom layout for the dialog box and call it
dialog.setContentView(R.layout.custom_dialog);
Related
I am building a dialog with DialogFragment, and I need to change the color of the shadow (mask), which is transparent and always around the main dialog content. Actually, almost all of the answers on the web is to change the dialog box color, but I need to change the shadow color from transparent black to others. Is there any way to do that?
image:
If you only want to change the alpha for the background then you can easily create a style with android:backgroundDimAmount attribute, like I did
<style name="CustomAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:backgroundDimAmount">0.5</item>
</style>
the value ranges 0-1 and then passing the style in your AlertDialog as
AlertDialog dialog = new AlertDialog.Builder(this, R.style.CustomAlertDialogStyle)
.setTitle("Title").setMessage("message").create();
dialog.show();
But if you want to change the background color as well then you can try this work around given by #Lee Han Kyeol
https://stackoverflow.com/a/29482234/5002610
I hope this will solve your issue.
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.
I'm trying to change the text color in dialog boxes, most commonly AlertDialog. I've tried every solution at these pages:
AlertDialog styling - how to change style (color) of title, message, etc
How can I change the color of AlertDialog title and the color of the line under it
How to change theme for AlertDialog
Most solutions work BELOW 5.0 but above it, and they don't seem to have any effect. What different attributes should I be changing for 5.0+?
The parent theme of my app is "Theme.AppCompat.Light.NoActionBar"
In your case, I think the dialog theme would work.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.YourDialogStyle;
You can specify your dialog theme just like the code above.
<style name="YourDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent">#color/primary</item>
<item name="android:textColor">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_dark</item>
</style>
Here is the example of theme for Dialog.
android:colorAccent will affect your text colors of negative or positive buttons.
android:textColor will affect your title text color of dialog.
android:textColorPrimary will affect your message color of dialog.
Another option is you can make your own custom layout for the dialog.
I am attempting to style a DialogFragment and, despite extensive research within SO, developer.android and elsewhere, it's just not working right.
I am sure that I have applied everything correctly; in my DialogFragment onCreateDialog, I am putting:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.FibroDialog));
and in values/styles.xml, I have:
<style name="FibroDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#drawable/panel_background</item>
</style>
and in values-v14/styles.xml, I have:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowBackground">#drawable/panel_background</item>
</style>
If I run that, I get the top row of dialogs in the image below, where nothing has changed at all, but I would expect the window to use my panel_background drawable. If I change windowBackground to background, I get the bottom row of dialogs in the image below, where it all goes wrong.
So how do I change this, so the entire dialogs have the purple background? I know I can use the layoutInflator and put a background colour in the layout, but that only does the middle bit.
I don't know if this is of any relevance, but the DialogFragment is launched from a SherlockFragment
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.