I am unable to change the selector color and other parts of the TimePicker.
So far, I can change header color and background but I am unable to change the innercircle and the textcolor.
Change custom theme link.
My code :
<TimePicker
android:id="#+id/tp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="clock"
android:headerBackground="#565466"
android:amPmBackgroundColor="#500126"
android:numbersBackgroundColor="#57e326"
android:numbersTextColor="#995394"
android:numbersSelectorColor="#675543"
android:textColorSecondary="#897530"
android:textColorPrimary="#359875"
/>
Basic mode
All you have to do is set your accent color in your Activity's theme:
<item name="colorAccent">#3333cc</item>
This will set all the colors for you so you wouldn't mess up the styling.
(This also means that you shouldn't set values like amPmBackgroundColor on your TimePicker directly, let Android do the things for you.)
Advanced mode
If you want to specify all the possible values separately, do the following:
First define this in your Activity's theme:
<item name="android:timePickerStyle">#style/Theme.MyTheme.TimePicker</item>
Then create the appropriate style:
<style name="Theme.MyTheme.TimePicker" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">clock</item>
<item name="android:headerBackground">#ff555555</item>
<item name="android:numbersTextColor">?android:attr/textColorPrimaryActivated</item>
<item name="android:numbersInnerTextColor">?android:attr/textColorSecondaryActivated</item>
<item name="android:numbersSelectorColor">?android:attr/colorControlActivated</item>
<item name="android:numbersBackgroundColor">#ff555555</item>
<item name="android:amPmTextColor">?android:attr/textColorSecondary</item>
</style>
Note that numbersInnerTextColor is only available from API level 23 and other styles (e.g. headerTextColor) can't be set (or at least I couldn't make it work).
I'd advise against using the "advanced" mode as the TimePicker should have the same colors as the containing Activity and doing otherwise might impact your UX in a bad way.
TimePicker material style:
TimePickerDialog material style with custom colors
<style name="MyTimePickerDialogStyle" parent="#style/ThemeOverlay.AppCompat.Dialog.Alert">
<item name="showTitle">false</item>
<item name="colorControlActivated">#ffd600</item>
<item name="colorAccent">#b71c1c</item>
<item name="android:textColorPrimary">#43a047</item>
<item name="android:textColorSecondary">#f44336</item>
</style>
TimePicker widget style
<style name="MyTimePickerWidgetStyle" parent="#android:style/Widget.Material.TimePicker">
<item name="android:headerBackground">#ffe082</item>
<item name="android:numbersTextColor">#b71c1c</item>
<item name="android:numbersInnerTextColor">#f44336</item>
<item name="android:numbersSelectorColor">#33691e</item>
<item name="android:numbersBackgroundColor">#ef9a9a</item>
<item name="android:amPmTextColor">#9c27b0</item>
</style>
For more information on TimePicker see http://www.zoftino.com/android-timepicker-example
Related
I am trying to understand how to change the look of all checkboxes within my application for a certain theme.
I would like to change the checkbox check color and the checkbox border color.
If I create this style:
<style name="MyCheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="colorControlNormal">#8AFFFFFF</item>
<item name="colorControlActivated">#android:color/white</item>
</style>
And apply it as a theme on my checkbox it works great.
<CheckBox
android:id="#+id/status_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="#style/MyCheckBox"/>
However I don't really want to apply that theme to every checkbox, I would like to set the theme for all checkboxes.
I tried to set the checkboxStyle in my theme however this doesn't work.
<style name="MyTheme" parent="Theme.AppCompat">
...
<item name="checkboxStyle">#style/MyCheckBoxStyle</item>
...
</style>
<style name="MyCheckBoxStyle" parent="Base.Widget.AppCompat.CompoundButton.CheckBox">
<item name="colorControlNormal">#8AFFFFFF</item>
<item name="colorControlActivated">#android:color/white</item>
</style>
Is there a way to set a default theme for all checkboxes?
Unfortunately, colorControlNormal and colorControlActivated are theme attributes, not style attributes, so they only work if they're defined in the view's theme. There is no way that I know of to set a "default theme" for all views of a certain type; attributes like checkboxStyle can only set a default style for all checkboxes. Additionally, you can't "trick" the system by writing something like:
<style name="MyTheme" parent="Theme.AppCompat">
...
<item name="checkboxStyle">#style/MyCheckBoxStyle</item>
...
</style>
<style name="MyCheckBoxStyle" parent="Base.Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:theme">#style/MyCheckboxTheme</item>
</style>
<style name="MyCheckboxTheme">
<item name="colorControlNormal">#8AFFFFFF</item>
<item name="colorControlActivated">#android:color/white</item>
</style>
Your choices are:
Modify colorControlNormal and colorControlActivated in your app's theme
Modify colorControlNormal and colorControlActivated in your activity's theme
Manually set the android:theme attribute to every checkbox you want to change (or to the parent viewgroup holding these checkboxes)
Edit: potential workaround
Depending on your exact requirements, you might be able to get away with this:
<style name="MyTheme" parent="Theme.AppCompat">
<item name="checkboxStyle">#style/MyCheckboxStyle</item>
</style>
<style name="MyCheckboxStyle" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="buttonTint">#8AFFFFFF</item>
</style>
This will change the color of every checkbox in your app without requiring the use of theme attributes. You can even use a color selector resource for buttonTint if you want different colors for checked/unchecked:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#android:color/white" android:state_checked="true"/>
<item android:color="#8AFFFFFF"/>
</selector>
I'm trying to style a TimePickerDialog for sdk 21+ (Lollipop). So far I've figured out how to change the default colorscheme in XML:
<style name="TimePickerTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#ff2d6073</item> <!-- no effect -->
<item name="colorPrimaryDark">#ff2d6073</item> <!-- no effect -->
<item name="colorAccent">#ff2d6073</item>
<item name="android:textColor">#ffD0D102</item>
<item name="android:textColorPrimary">#ffD0D102</item>
</style>
This works but I'm looking for a guide or documentation for all the properties I can change.
AccentColor does the basic color scheme
TextColorPrimary does the text color
But what property, for example, do I need to change the big text in the 'header' of the dialog (where the current selected time is displayed)?
Is there some documentation that lists all the possible things you can change?
After digging through the AOSP theme and style xml files and a lot of googling I made some progress. I am now able to style most(!) things.
So this is a partial answer, not all the way there yet. But here's how far I got:
You can see that I'm now able to theme the header, the un(!)selected time part (minutes in this case), the circle, the numbers in that circle and the 'hand' (or selector). Oh, and the buttons are styled, too.
Let me explain how I got things working, first: the important thing is that you can't override things directly from you app's theme OR from a (alert)dialog theme/style. You have to go from one to the next, so to speak.
Example:
AndroidManifest.xml: Set custom theme for app and/or activity
<activity>
android:theme="#style/Theme.MyTheme"
</activity>
values-v21/styles.xml: (where your custom theme resides): set the timePickerDialogTheme
<style name="Theme.MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">#style/TimePickerDialogTheme</item>
</style>
Then below that, define the timePickerDialogTheme and set the timePickerStyle:
<style name="TimePickerDialogTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->
<item name="android:timePickerStyle">#style/TimePickerDialogStyle</item>
</style>
Now you can define most of the styling here..
<style name="TimePickerDialogStyle" parent="#android:style/Widget.Material.Light.TimePicker">
<item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->
<item name="android:timePickerMode">clock</item>
<item name="android:headerBackground">#ff2d6073</item>
<item name="android:headerTimeTextAppearance">#style/TextAppearance.TimePickerDialogStyle.TimeLabel</item> <!-- TimePicker Time *TextAppearance* -->
<item name="android:numbersTextColor">#ff000000</item>
<item name="android:numbersSelectorColor">#ff2d6073</item>
<item name="android:numbersBackgroundColor">#ffdddddd</item>
</style>
The important line in the above is:
<item name="android:headerTimeTextAppearance">#style/TextAppearance.TimePickerDialogStyle.TimeLabel</item>
Because if you want to style the text (well, time, actually) in the header you need to define the headerTimeTextAppearance:
<style name="TextAppearance.TimePickerDialogStyle.TimeLabel" parent="#android:style/TextAppearance.Material">
<item name="android:textSize">60sp</item> <!-- from -->
<item name="android:textColor">#ffD0D102</item>
</style>
Now, if you take a look at the Widget.Material.TimePicker in AOSP styles.xml (ctrl-f 'timepicker' until you find it) you'll notice a bunch of other properties that you should be able to modify:
headerTimeTextAppearance
headerAmPmTextAppearance
headerSelectedTextColor
headerBackground
numbersTextColor
numbersBackgroundColor
amPmTextColor
amPmBackgroundColor
amPmSelectedBackgroundColor
numbersSelectorColor
Most of these work (as long as you prepend 'android:' for each of them) BUT I could not get 'headerSelectedTextColor' to work. I got a compile error saying something like "could not match property bla bla". Also, if you look at my example above, I hardcoded the textSize for the 'headerTimeTextAppearance' property because the '#dimen/timepicker_ampm_label_size' value threw errors.
In short: most of the things are listed above and how to get them working. But not all is clear. So I'd still see that complete documentation/guide :)
Android TimePicker material style with custom colors below, you can see http://www.zoftino.com/android-timepicker-example for TimePicker usage and styles.
<style name="MyAppThemeFour" parent="Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">#style/MyTimePickerDialogStyle</item>
</style>
<style name="MyTimePickerDialogStyle" parent="#style/ThemeOverlay.AppCompat.Dialog.Alert">
<item name="showTitle">false</item>
<item name="colorControlActivated">#ffd600</item>
<item name="colorAccent">#b71c1c</item>
<item name="android:textColorPrimary">#43a047</item>
<item name="android:textColorSecondary">#f44336</item>
</style>
When using version 1.5.0 of the Material Design Library for Android, I've found that I can get most of the theming with using this particular style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTimePickerTheme" parent="ThemeOverlay.MaterialComponents.TimePicker">
<item name="android:textColor">#FF121212</item>
<item name="android:textColorPrimary">#FF121212</item>
<item name="android:textColorSecondary">#FFF9F9F9</item>
<item name="colorAccent">#FF121212</item>
<item name="colorControlNormal">#FF121212</item>
<item name="colorPrimary">#FF121212</item>
<item name="colorSurface">#FFF9F9F9</item>
</style>
</resources>
This will yield in a generic - non colored - Dialog which works for white theme. For dark theme, simply invert the colors.
I've also asked here to have dynamic theming supported for this component.
Example screenshot using the above style:
I'm trying to apply some styles to my app. I've created a custom theme for the ActionBar using this actionbarstylegenerator.
But I want to change also in my app, the stock blue Holo color, to a red one, at least on buttons.
So, I have the custom theme for the ActionBar (Compat), and for the other side, a custom theme to change the Holo color.
In my app, I have defined the custom theme for the Actionbar, and I want to set the custom Holo theme inside the Actionbar's theme, but I don't know how to call, or where can I find the item name's whose define the variable you want to modify.
This is, I need to set this:
<style name="ColorTheme" parent="android:Theme.Black">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>
</style>
Inside of this:
<style name="Theme.CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="actionBarItemBackground">#drawable/ab_selectable_background</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionDropDownStyle">#style/DropDownNav</item>
<item name="actionBarStyle">#style/ActionBar.Transparent</item>
<item name="actionModeBackground">#drawable/cab_background_top_customactionbartheme</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_customactionbartheme</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode</item>
</style>
Maybe you need to do this?
<style name="ColorTheme" parent="Theme.CustomActionBarTheme">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>
I want to overload how an android Button looks, except I want to overload only one attribute i.e. the android:background. I know I could write something like:
<style name="App_TextButtonStyle" parent="???">
<item name="android:background">#drawable/filled_roundededges_nostroke</item>
</style>
Where parent="???" specifies which style I inherit from. My question is which style should I inherit from do that I get everything from the android default style for buttons and just define a new background.
I have used style for buttons without specifying "parent" attribute
<style name="BigButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:background">#drawable/backbutton</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">8pt</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_margin">10pt</item>
</style>
I think it could be enough for you to define your style without "parent".
This is mostly for future visitors, I found a solution to the problem:
<style name="App_TextButtonStyle" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/filled_roundededges_nostroke</item>
</style>
#android:style/Widget.Button references the default style of the button in the currently selected theme. You could also use the holo widget button style #android:style/Widget.Holo.Button (available since api 11).
You might want to look in <android-sdk-install-folder>/platforms/android-XX/data/res/values for the files styles.xml and themes.xml to check out all styles android uses for a given platform version.
I have a style that includes textColor, textSize, textStyle and typeface. When applied directly to an EditText widget, the color of the text is as specified (as well as the other attributes), but when applied as a theme to the activity or the entire application, the size is fine but the color is not applied. What I am missing?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="fap" parent="android:Theme.Holo">
<item name="android:textSize">24sp</item>
<item name="android:textColor">#FF0000</item>
<item name="android:textStyle">normal</item>
<item name="android:typeface">normal</item>
</style>
</resources>
This is quite simple : you are not overriding android default style, your just creating a new one which extends android:Widget.EditText. Thus, the style is not applied.
To correct this, into your theme definition, just add :
<item name="android:editTextStyle">#style/fap</item>
Now, each time Android instanciate an EditText, when it load default style values, it will find your fap style.
Edit:
searching through android's source code is very usefull. Check https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/attrs.xml
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/themes.xml
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/styles.xml
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/EditText.java
for example.
EditText widget just can't get these parameters from an activity theme. It gets its default style from the android:editTextStyle parameter of the activity theme. So you have to create your own style:
<style name="MyEditText" parent="android:Widget.EditText">
<item name="android:textSize">24sp</item>
<item name="android:textColor">#FF0000</item>
<item name="android:textStyle">normal</item>
<item name="android:typeface">normal</item>
</style>
And then set it as EditText style in the activity theme:
<style name="fap" parent="android:Theme.Holo">
<item name="android:editTextStyle">#style/MyEditText</item>
</style>
Hope this will work because I haven't tried this code.