I've setup a style for a DatePickerDialog background, and it shows up differently on Nexus 5 (Marshmallow):
The style I'm using is:
<style name="datepicker">
<item name="android:background">#color/android:white</item>
<item name="android:textColorPrimaryInverse">#color/android:black</item>
<item name="android:textColorPrimary">#color/android:black</item>
<item name="android:textColorSecondary">#color/colorAccent</item>
<item name="android:textColorSecondaryInverse">#color/colorAccent</item>
<item name="android:textColorTertiary">#color/android:black</item>
</style>
(colorAccent is gold)
The year at the top is supposed to be controlled by textColorSecondary, but now it's showing up as black. And the background of the header is grey, which I'd like white. What are the names of these items for Marshmallow?
You can use this style and theme config for change the text and header color. However, I think it is not more beautiful than default dialog picker.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:datePickerDialogTheme">#style/MyDatePickerDialogTheme</item>
</style>
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
<item name="android:textColorPrimaryInverse">#000</item> <!-- header date, month color && calendar text highlight color -->
<item name="android:textColorSecondaryInverse">#000</item> <!-- header year color -->
<item name="android:colorAccent">#B09A60</item> <!-- button color -->
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">#fff</item> <!-- header background color -->
</style>
Tested on API 22, 23, 25
The names of these items are the same for all android version > Andoid 5.0 Lollipop to be complient with Material design.
You can try to add a parent and override headerBackground for the background :
<style name="datepicker" parent="#android:style/Widget.Material.DatePicker">
<item name="android:background">#color/android:white</item>
<item name="android:textColorPrimaryInverse">#color/android:black</item>
<item name="android:textColorPrimary">#color/android:black</item>
<item name="android:textColorSecondary">#color/colorAccent</item>
<item name="android:textColorSecondaryInverse">#color/colorAccent</item>
<item name="android:textColorTertiary">#color/android:black</item>
<item name="android:headerBackground">#color/android:white</item>
</style>
However i think the year color is the same that textColorPrimary.
Hope this helps.
Related
I am using the Material-Component Date Range Picker in my Android app and I want to customize the header layout. I have tried adding the materialCalendarHeaderLayout item in my custom style, but I am not sure how to use it properly as I am new on the Android.
I want to hide the header.
Want a custom Year & Month button. (Optional task)
I used the themes.xml to modify the date picker to appear as a popup instead of fullscreen.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/orange</item>
<item name="colorPrimaryVariant">#color/black</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/orange</item>
<item name="colorSecondaryVariant">#color/black</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#color/black</item>
<!-- Date range picker -->
<item name="materialCalendarFullscreenTheme">#style/CustomThemeOverlay_MaterialCalendar_Fullscreen</item>
</style>
<!-- Popup Menu theme -->
<style name="PopupMenuBlackBackground" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:popupMenuStyle">#style/PopupMenuBlackBackground.Menu</item>
<item name="android:fontFamily">#font/poppins_regular</item>
<item name="android:popupElevation">5dp</item>
<item name="android:radius">5dp</item>
</style>
<style name="PopupMenuBlackBackground.Menu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#color/blackDark</item>
<item name="android:popupElevation">5dp</item>
<item name="android:radius">5dp</item>
</style>
<!-- Date range picker fullscreen -->
<style name="CustomThemeOverlay_MaterialCalendar_Fullscreen"
parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="materialCalendarStyle">#style/Custom_MaterialCalendar.Fullscreen</item>
</style>
<style name="Custom_MaterialCalendar.Fullscreen"
parent="#style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="android:windowFullscreen">false</item>
</style>
</resources>
Expexted Date range picker:
Can someone guide me on how to achieve this customization? Any help or suggestions would be appreciated.
Thank you in advance.
To hide the header layout you can use:
<style name="App.MaterialCalendarTheme" parent="ThemeOverlay.Material3.MaterialCalendar">
<item name="materialCalendarHeaderLayout">#style/App.Material3.MaterialCalendar.HeaderLayout</item>
</style>
<style name="App.Material3.MaterialCalendar.HeaderLayout" parent="#style/Widget.Material3.MaterialCalendar.HeaderLayout">
<item name="android:visibility">gone</item>
</style>
How to increase the text size of RadioGroup in AlertDialog made using setSingleChoiceItems?
This is what we tried but did not work.
<style name="DialogButtonStyle" parent="Widget.Material3.Button.TextButton.Dialog" tools:keep="#style/DialogButtonStyle">
<item name="android:textColor">#color/orange</item>
</style>
<!-- AlertDialog theme on both light and night mode -->
<style name="AppDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog" tools:keep="#style/AppDialog">
<!-- Background color -->
<!--<item name="colorSurface">#color/colorWhite_Primary</item>-->
<!-- Message color -->
<item name="colorOnSurfaceVariant">#color/white_black</item>
<item name="buttonBarPositiveButtonStyle">#style/DialogButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/DialogButtonStyle</item>
<item name="materialAlertDialogBodyTextStyle">#style/AppDialog.Body</item>
<item name="alertDialogStyle">#style/MaterialAlertDialog.App</item>
</style>
<style name="MaterialAlertDialog.App" parent="MaterialAlertDialog.Material3" tools:keep="#style/MaterialAlertDialog_App">
<item name="shapeAppearance">#style/ShapeAppearance.App.MediumComponent</item>
<item name="shapeAppearanceOverlay">#null</item>
</style>
<style name="AppDialog.Body" parent="#style/MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textAppearance">#style/AppDialog.Body.Appearance</item>
</style>
<style name="AppDialog.Body.Appearance" parent="#style/TextAppearance.MaterialComponents.Subtitle1">
<item name="android:textSize">34sp</item>
</style>
I found the answer here, it should be checkedTextViewStyle instead of materialAlertDialogBodyTextStyle. It's a shame that Material 2 documentation is better than Material 3.
I want to change the default textColor of all text in my App. e.g. for all buttons, textViews, EditText's etc. in my App. Before moving to Material3, this was done using:
themes.xml
<style name="MyThemeName" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#color/black</item>
Now it doesn't work anymore. How do I do it now? The project is a default Android project:
<style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
<!-- This is not working -->
<item name="android:textColor">#color/black</item>
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
I can do it like this, but that is not the answer I'm looking for:
<style name="BaseStyle" parent="android:Widget.Material.Light.Button.Borderless"/>
<style name="Widget.Button.MyCompanyName" parent="BaseStyle">
<item name="android:textColor">#android:color/black</item>
</style>
The above button style I only define the textColor when it differs from the default color that I want.
The text color of the elements will change based on what type of element it is being shown on. for example if you are using the material button by default the button color will be "colorPrimary" and the button text color will be "colorOnPrimary". and similar to this if an element color uses the "colorBackground" its text color will be "colorOnBackground".
in my case i was able to control the text color of all the elements i use by adding a value for the following styles:
<item name="colorOnPrimary">#000000</item>
<item name="colorOnPrimaryContainer">#000000</item>
<item name="colorOnSecondary">#000000</item>
<item name="colorOnSecondaryContainer">#000000</item>
<item name="colorOnBackground">#000000</item>
<item name="colorOnSurface">#000000</item>
<item name="colorOnSurfaceVariant">#000000</item>
<item name="android:textColorPrimary">#000000</item>
<item name="titleTextColor">#000000</item>
you can read more about this in "Typography and iconography colors" section Here
Does the below work? Not sure textViewStyle covers ALL texts. You might need some extra things like <item name="materialButtonStyle"> too.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:textViewStyle">#style/MyTextView</item>
</style>
<style name="MyTextView" parent="Widget.MaterialComponents.TextView">
<item name="android:textColor">#android:color/black</item>
</style>
I cannot seem to get what I want no matter how much reading I do on this subject - yet what I want is quite simple.
I am applying a global style to my app based on AppCompat NoActionBar. This gives white text and I want to change it to a dark colour. Here is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorSecondary</item>
<item name="android:textColor">#ff4400</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
This is fine. The text colour is changed to a dark colour everywhere (set to red here so I can see what's happening). Unfortunately this also overrides all of the text colouring for buttons. Disabled buttons show the dark colour and there is no way to distinguish them from enabled buttons. I've tried applying styles to buttons but the textColor always overrides the disabled colour.
I'm at a bit of a loss as to how to proceed. I don't want to apply a selector on every button nor colour all the buttons individually by setting a style on each one. I want an overall global colour change - which Android seems to have made exceptionally difficult.
I eventually managed to get it to work. I had to use a selector. I provide my solution below.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorSecondary</item>
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:textColorSecondary">#color/secondary_text_color_selector</item>
<item name="alertDialogTheme">#style/ThemeDialog</item>
</style>
<style name="ThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:background">#color/colorTertiary</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
I am trying to change the style of the app but everything is grey instead. What's the problem?
I am using android studio. This project was originally on eclipse. I am not building it using Lollipop on Android Studio
<application
android:name=".MainApplication"
tools:replace="android:icon,android:theme"
android:label="#string/app_name"
android:logo="#drawable/ic_logo"
android:theme="#style/Theme.Materialred" >
styles_materialred.xml:
<resources>
<style name="Theme.Materialred" parent="#style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_materialred</item>
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Materialred</item>
<item name="actionDropDownStyle">#style/DropDownNav.Materialred</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Materialred</item>
<item name="actionModeBackground">#drawable/cab_background_top_materialred</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_materialred</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Materialred</item>
</style>
<style name="ActionBar.Solid.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_materialred</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_materialred</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="ActionBar.Transparent.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="PopupMenu.Materialred" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
</style>
<style name="DropDownListView.Materialred" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ActionBarTabStyle.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_materialred</item>
</style>
<style name="DropDownNav.Materialred" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_materialred</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
<item name="android:dropDownSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ProgressBar.Materialred" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_materialred</item>
</style>
<style name="ActionButton.CloseMode.Materialred" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_materialred</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Materialred.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
</style>
Set the color in this way in action bar theme.
<item name="colorPrimary">#color/primaryDef</item>
Read this interesting article of Chris Banes https://chris.banes.me/2014/10/17/appcompat-v21/#migrationfromprevioussetup
I was having this problem and just noticed that there was a separate styles.xml file for Lollipop. It was originally hidden by the default file, but clicking the arrow reveals it. Editing this one works as expected.
You have to use this:
<style name="AppThemeRandom" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- The primary branding color for the app. By default, this is the color applied to the
action bar background. -->
<item name="colorPrimary">#color/md_indigo_500</item>
<!-- Dark variant of the primary branding color. By default, this is the color applied to
the status bar (via statusBarColor) and navigation bar (via navigationBarColor). -->
<item name="colorPrimaryDark">#color/md_indigo_700</item>
<!-- Bright complement to the primary branding color. By default, this is the color applied
to framework controls (via colorControlActivated). -->
<item name="colorAccent">#color/md_pink_A200</item>
<!-- The color applied to framework controls in their normal state. -->
<item name="colorControlNormal">#color/md_amber_500</item>
<!-- The color applied to framework controls in their activated (ex. checked) state. -->
<item name="colorControlActivated">#color/md_green_500</item>
<!-- The color applied to framework control highlights (ex. ripples, list selectors). -->
<item name="colorControlHighlight">#color/md_teal_500</item>
<!-- The color applied to framework buttons in their normal state. -->
<item name="colorButtonNormal">#color/md_red_500</item>
<!-- The color applied to framework switch thumbs in their normal state. -->
<item name="colorSwitchThumbNormal">#color/md_black_1000_50</item>
<!-- Inactive track color(75% transparency) -->
<item name="android:colorForeground">#color/md_black_1000_75</item>
</style>
Obviously, choose your colors, it is a random theme to check all colors in status bar, toolbar, widgets like checkbox, etc.