Im using Theme.Holo.Light.DarkActionBar but I dont really like the Light Dialogs/AlertDialogs.
I want to change every Dialog to the dark Holo Dialog.
<style name="CustomDialogTheme" parent="#android:style/Theme.Holo.Dialog">
<item name="#android:background">#9933CC</item>
<item name="#android:textColor">#02FA07</item>
</style>
<style name="Holo.Light.DarkActionBar" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:dialogTheme">#style/CustomDialogTheme</item>
<item name="android:alertDialogStyle">#style/CustomDialogTheme</item>
</style>
Thats what I tried but it has no effect on any Dialogs.
Ok nvm Im stupid its android:alertDialogTheme instead of android:alertDialogStyle. But this messes up the Preference Dialogs, so I just keep using the Light Dialogs.
In AndroidManifest.xml under the application tag, add this line :
android:theme="Holo.Light.DarkActionBar"
The issue is that the styles you're changing android:background and android:textColor are not dialog attributes.
You can see a full list here under Theme.Holo.Dialog on line 1617.
The ones you have to change are probably android:windowBackground and textAppearance
Related
My app theme is set up like this:
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorOnSurface">#color/appColorOnSurface</item>
...
</style>
But when I use MaterialAlertDialogBuilder the text contrast is very poor (because material dialog uses colorOnSurface with 60% alpha, instead of textColorPrimary). So I tried to use this ThemeOverlay:
<style name="ThemeOverlay.App.Dialog.HighContrast" parent="ThemeOverlay.MaterialComponents.Dialog">
<item name="colorOnSurface">#color/appColorOnSurfaceHighContrast</item>
</style>
and applying it like this:
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="materialAlertDialogTheme">#style/ThemeOverlay.App.Dialog.HighContrast</item>
<item name="colorOnSurface">#color/appColorOnSurface</item>
...
</style>
However, this causes problems when displaying a list of items in the dialog. Each item touch area is limited to the area of text being displayed instead of stretching the width of the dialog like normal.
Furthermore, the theme does not appear to be Material, but rather AppCompat style.
Why does the ThemeOverlay approach cause the unexpected touch area (as if WRAP_CONTENT) issue? Is that not the correct way to apply a ThemeOverlay? Or is there another way to get the alert dialog to use #color/appColorOnSurfaceHighContrast?
I fixed this by using ThemeOverlay.MaterialComponents.MaterialAlertDialog instead of ThemeOverlay.MaterialComponents.Dialog.Alert, and also using materialAlertDialogBodyTextStyle to make sure only the dialog text body was being styled:
<style name="ThemeOverlay.App.Dialog.HighContrast" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogBodyTextStyle">#style/MaterialAlertDialog.App.Body.Text.HighContrast</item>
</style>
<style name="MaterialAlertDialog.App.Body.Text.HighContrast" parent="#style/MaterialAlertDialog.MaterialComponents.Body.Text">
<item name="android:textColor">#color/appColorOnSurfaceHighContrast</item>
</style>
But why does AndroidStudio auto-complete only show ThemeOverlay.MaterialComponents.Dialog.Alert and not ThemeOverlay.MaterialComponents.MaterialAlertDialog?
Note: there were actually two issues going on here:
Changing the parent ThemeOverlay from ThemeOverlay.MaterialComponents.Dialog to ThemeOverlay.MaterialComponents.Dialog.Alert fixed the touch area issue, but I was still getting an AppCompat (non-Material) theme.
Changing the parent ThemeOverlay from ThemeOverlay.MaterialComponents.Dialog.Alert to ThemeOverlay.MaterialComponents.MaterialAlertDialog fixed the theme to make it appear Material.
UPDATE: It looks like ThemeOverlay.MaterialComponents.Dialog.Alert is for use with alertDialogTheme and ThemeOverlay.MaterialComponents.MaterialAlertDialog is for use with materialAlertDialogTheme. See: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/dialog/res/values/themes.xml#L60
However, that still doesn't explain why the latter doesn't auto-complete.
I'm trying to style the dialog box that appears when I select an EditTextPreference in my SettingsActivity. So far I have been able to change the colour of the two buttons and the background with:
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(0xffffffff);
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(0xffffffff);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.blue_background);
But I am so far unable to change the title at the top of the dialog.
The colour of the 'Zone' title is being retrieved from a style I use for the preference list, it's being inherited and I can't figure out how to assign it a style that will change that title colour
<style name="MyPreferenceTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#color/care_call_white</item>
<item name="android:textColor">#drawable/text_colour_state</item>
<item name="android:textColorSecondary">#drawable/text_colour_state</item>
</style>
Can anyone help with a style that could do this? Or with some code that could possibly set it instead? All my dialog boxes are styled the same but this one is trickier as it's part of the Preference so I can't customise it the same way I did with the others.
Just to clarify, the only thing that needs changing is the "Zone" title.. I would like it to be white.
With new AndroidX Preference library there is no onPrepareDialogBuilder in EditTextPreference.
I've proceeded in this way:
My base app theme:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
//add here your properties
</style>
my preference theme:
<style name="AppTheme.Settings">
<!-- This will change the opening dialogs for EditTextPreference -->
<item name="alertDialogStyle">#style/Theme.AlertDialog.Default</item>
</style>
in my case Theme.AlertDialog.Default is a custom Dialog theme with with parent ThemeOverlay.MaterialComponents.MaterialAlertDialog
Then in your AndroidManifest.xml simply apply the theme to the the Activity which handle the preferences
Sorted.
I created a CustomEditTextPreference class that inherited EditTextPreference and then overrode
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.getContext().setTheme(R.style.PreferenceThemeDialog);
super.onPrepareDialogBuilder(builder);
}
and changed the style in the builders context with
<style name="PreferenceThemeDialog">
<item name="android:textColor">#color/care_call_white</item>
</style>
One way you can change the theme or the title of a preference is by finding it within your settings activity or fragment and then editing the attributes.
To edit the theme you would do this:
findPreference<EditTextPreference>(YOUR_KEY_GOES_HERE)?.context?.setTheme(YOUR.THEME.GOES.HERE)
To change the title you would do this:
findPreference<EditTextPreference>(BACKGROUND_SYNC_PERIOD_KEY)?.dialogTitle = YOUR_TITLE_GOES_HERE
Both of these are in kotlin but it is essentially the same thing in java.(you can paste this into android studio and it should format it).
<style name="cust_dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/dialog_title_style</item>
</style>
<style name="dialog_title_style" parent="android:Widget.TextView">
<item name="android:background">#android:color/black</item>
<item name="android:padding">10dp</item>
</style>
And you can instantiate dialog:
Dialog dialog=new Dialog(this,R.style.cust_dialog);
dialog.setContentView(R.layout.fragment_features_dialog);
dialog.setTitle(R.string.features);
Now the dialog shows up with black title background color.
I have a spinner in a Holo theme dialog and am trying to change the text colour because it is very hard to read:
I have looked at android styles.xml, as well as many other answers, and believe that I am setting the custom style correctly; but it's just not getting picked up.
This is an extract from the dialog layout file where the spinner lives:
<Spinner
android:id="#+id/spn_Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/dose_type_options"
style="#style/DialogSpinner" />
And these are the relevant entries in styles.xml in the values-v14 folder:
<style name="DialogSpinner" parent="#android:style/Widget.Holo.Spinner">
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MySpinnerItem" parent="android:Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearanceSpinnerItem</item>
</style>
<style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
</style>
The dialog itself is forced to the Holo dark theme by using:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
</style>
Can anyone identify why the spinner text isn't white?
I have looked at other solutions, which suggest changing the colour in code, but this app supports 2.3.* upwards, so for those non-holo versions black text is fine, hence trying to do it by styles.
Thanks
Updated using answer from Woda below
The text colour of the initial value of the spinner is now white, which goes a long way to highlighting that there is a spinner there for the user:
But the text colour of the selectable items is still black. I guess it's not a massive deal, at least the existence of the spinner has been affirmed by getting the initial text changed to white. But I would be interested to know why the items are still black, and how to change them to white.
Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:
theme.xml:
<style name="exampleTheme" parent="android:Theme.Holo.Light">
<item name="android:spinnerItemStyle">#style/SpinnerItem_example</item>
...
</style>
style.xml:
<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#000000</item>
</style>
Update:
Taking a deeper look into the styles.xml brought me this:
<style name="Widget.DropDownItem.Spinner">
<item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>
<style name="Widget.DropDownItem">
<item name="android:textAppearance">#style/TextAppearance.Widget.DropDownItem</item>
<item name="android:paddingStart">#dimen/dropdownitem_text_padding_left</item>
<item name="android:paddingEnd">#dimen/dropdownitem_text_padding_right</item>
<item name="android:gravity">center_vertical</item>
</style>
So you probably need to customize the Widget.DropDownItem and accept it in your theme.
...
<item name="dropDownItemStyle">#android:style/Widget.DropDownItem</item>
...
For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.
themes.xml
styles.xml
I fixed it by calling
mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());
Hope this helps someone ;)
You can access the internal TextView in code without changing any styles. This is how I handled enabling and disabling Spinners
The .getSelectedView() did not work for me. So I tricked the Spinner to "show" being disabled.
You will need to define your own colors for the "disabled" look.
For Example:
R.color.blue_text //means enabled
R.color.gray_text //means disabled
So to disable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
mySpinner.setEnabled(false);
mySpinner.setFocusable(false);
To enable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
mySpinner.setEnabled(true);
mySpinner.setFocusable(true);
The getChildAt(0) function allows you to access the first item in the spinner, which is what you show on the screen as a TextView.
You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.
I want to change color of the blue parts in the following image:
I know how to use custom styles, I just need to know what are called the properties of these blue parts (I mean something like <item name="android:background">#FF0000</item> ) thx
What I really want to achieve is demonstrated here:
You may inherit the theme used from Android code and change particulars within that.
http://developer.android.com/guide/topics/ui/themes.html
<style name="GreenText" parent="#android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
parent holds the value of the default theme. In your case it will be the Dialog theme for Holo.
I am trying to set custom background colour to title of Theme.Holo.Light application with below xml. But it doesn't work.
Theme.Holo.Light somehow overrides #style/WindowTitleBackground
if I set parent to just android:Theme, it works fine. I want to ave Halo.Light theme but with different background. I have seen custom background layout samples but as I am learning I don't want to go in to that.
Any help appreciated.
Thanks
<style name="theme" parent="android:Theme.Holo.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#000000</item>
</style>
when you use android:background, it must be drawable resource, so using value such as #ff234562 directly will not be valid,in fact you should define the value in colors.xml first,then use like this
<item name="android:background">#color/green</item>
It seems like Android uses bitmaps for that value (either #null or #android:drawable/title_bar).
Try creating a black png and use it instead of the color code:
<style name="WindowTitleBackground">
<item name="android:background">#drawable/black</item>
</style>