I find the spinner to be very frustrating to use programmatically and to style
I'd like to change the styling from the first picture (where the arrow is pointing down in the center) to the second picture (where the arrow is angled and it's located in the bottom right).
How do I do this?
// styling for spinner
<style name="spinner_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:spinnerMode">dialog</item>
<item name="android:layout_marginBottom">0.05dp</item>
<item name="android:background">?android:selectableItemBackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#null</item>
</style>
Use Widget.Holo.Spinner as your parent style for the spinner:
<style name="spinner_style" parent="#android:style/Widget.Holo.Spinner">
<!-- YOUR STYLE HERE -->
</style>
Related
I am referring to the transparent gray color that comes on radio button when focused
I tried most of the style attributes with color for the RadioButton.
<style name="Widget.App.RadioButton" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:shadowRadius">50</item>
<item name="android:buttonTint">#color/Red</item>
<item name="colorPrimarySurface">#color/Green</item>
<item name="colorOnSurface">#color/md_red_800</item>
<item name="colorSecondary">#color/md_red_400</item>
<item name="android:colorFocusedHighlight">#color/md_purple_500</item>
</style>
Basically, you can set transparent background to your RadioButton groups.
To do that, you can add this line to your custom style.
<item name="android:background">#android:color/transparent</item>
So, your custom style will look like this;
<style name="Widget.App.RadioButton" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:shadowRadius">50</item>
<item name="android:buttonTint">#FF3333</item>
<item name="colorPrimarySurface">#android:color/darker_gray</item>
<item name="colorOnSurface">#android:color/holo_red_light</item>
<item name="colorSecondary">#android:color/holo_red_dark</item>
<item name="android:colorFocusedHighlight">#android:color/holo_purple</item>
<item name="android:background">#android:color/transparent</item>
</style>
I would like to avoid applying a style to the toolbars in all layouts, so I have a style I created for it:
<style name="DarkToolbar" >
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
And I added it to my theme as follows:
<style name="Theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
<item name="colorAccent">#color/blue</item>
<item name="android:toolbarStyle">#style/DarkToolbar</item>
</style>
This is the resulting toolbar:
As you can see, the title and subtitle have the wrong formatting. If I remove the style from the theme and apply it directly to the toolbar in the layout, I get the following result instead:
Both images use the same style. One is applied through the app theme with
<item name="android:toolbarStyle">#style/DarkToolbar</item>
and the second one is applied directly to the toolbar with
style="#style/DarkToolbar"
Does anyone know the reason for the difference?
Also, does anyone know why the
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
Are not being applied?
Thanks
Add parent="Widget.AppCompat.Toolbar" to your toolbar style. It is default style for toolbar.
For example:
<style name="DarkToolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
I think this has to do with
< item name="android:theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar< /item>
in your style
I personally find styling toolbar text quite complicated, so mostly end up with my own TextView. How about using your own TextView inside toolbar. It would be easy, though a bit lengthy.
You are setting parent as no action bar in your theme, as this will give you the run time exception and null point exception as there is no action bar or tool bar to set the title/sub-title. Try adding parent in your theme with toolbar or action bar likes this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DarkToolbar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
<item name="colorAccent">#color/blue</item>
<item name="android:toolbarStyle">#style/DarkToolbar</item>
</style>
</resources>
I created a custom theme for the action bar that makes it white, and having a tad bit of trouble, and I have not been able to find the solution. First of all I want the 'options button' to be red, like the text below. but especially I want when clicked the whole row to be highlighted, not like it is shown in the picture:
Sso here is the code for the theme I'm using:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:background">#color/White</item>
<item name="android:textColorLink">#color/White</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/White</item>
<item name="android:textColor">#color/Red</item>
</style>
</resources>
I was hoping I could also get the red text to be aligned right, and have tried multiple alignment methods with no luck.thanks.
You need styles for android:actionMenuTextColor to change the "options" text color and android:textAppearanceLargePopupMenu to change the PopupMenu text color.
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#android:color/holo_red_dark</item>
<item name="android:textAppearanceLargePopupMenu">#style/TextAppearance.Red.PopupMenu.Large</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
</style>
<style name="TextAppearance.Red.PopupMenu.Large" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#android:color/holo_red_dark</item>
</style>
<style name="PopupMenu.Example" parent="#android:style/Widget.ListPopupWindow">
<item name="android:popupBackground">#drawable/your_background</item>
<!-- Or use -->
<item name="android:popupBackground">#android:color/white</item>
</style>
I am having problem setting the drawable for the divider. My style.xml looks like this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="HCLTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/HCLActionBarStyle</item>
<item name="actionBarStyle">#style/HCLActionBarStyle</item>
<item name="android:actionBarTabBarStyle">#style/HCLActionBarTabBarStyle</item>
<item name="android:actionBarTabStyle">#style/HCLActionBarTabStyle</item>
</style>
<style name="HCLActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/hcl_actionbar_drawable</item>
<item name="background">#drawable/hcl_actionbar_drawable</item>
<item name="android:titleTextStyle">#style/HCLActionBarTitle</item>
</style>
<style name="HCLActionBarTabBarStyle" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/divider</item>
<item name="android:dividerPadding">0dp</item>
</style>
<style name="HCLActionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/action_bar_tab_style</item>
</style>
<style name="HCLActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
In the HCLActionBarTabBarStyle I'm setting the #drawable/divider as the tab divider. This drawable is a 9patch image, a vertical black line.
Before i set the divider drawable in the xml I'm getting the normal white divider like this:
After i set the drawable in the styles.xml i get this:
So as you can see the divider just gets wider, and its not the black vertical line from the 9patch image. I'm not even sure what the drawable for the divider has to be? A picture or layer list, or can it be a color? In fact i tried all of these 3 but with no success.
Use the property of "actionBarDivider" on the custom style.
Something like below
<style name="AppTheme" parent="AppBaseTheme">
<!-- You app specific customization -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/menu_state_list</item>
<item name="android:actionBarTabStyle">#style/tabStyle</item>
<item name="android:actionBarTabTextStyle">#style/tabTextColor</item>
<!-- Set it like this -->
<item name="android:actionBarDivider">#drawable/verticle_marker_thin</item>
</style>
create tab divider picture
in styles add an item shown below
<item name="android:actionBarTabBarStyle">#style/customTabBar</item>
code for devider in action bar tab indicator
<style name="customTabBar" parent="#style/Widget.AppCompat.ActionBar.TabBar">
<item name="android:showDividers">middle</item>
<!-- give your divider here -->
<item name="android:divider">#drawable/tabindicator</item>
<item name="android:dividerPadding">0dp</item>
where #drawble/tabindicator is a picture in drawble
I am trying to achieve 2 things
White Text for Menu Items, Title text color works
Text Shadows for Title and Menu item
All this on XML.
What works, after experiments?
Custom Action bar layout works just fine with shadows.
Text color for all Tiles works but text shadow has no effect
Text color for Menu item has no effect anywhere. In the example code when I declare MenuTextStyle in the main Theme tag, I am able to change text size but not color.
<style name="Theme.SexyApp" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.SexyApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.SexyApp.ActionBar</item>
<item name="android:actionBarItemBackground">#drawable/list_state</item>
<item name="actionBarItemBackground">#drawable/list_state</item>
<item name="android:actionMenuTextAppearance">#style/Theme.SexyApp.ActionBar.MenuTextStyle</item>
<item name="actionMenuTextAppearance">#style/Theme.SexyApp.ActionBar.MenuTextStyle</item>
</style>
<style name="Widget.SexyApp.ActionBar" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="android:displayOptions">showHome|useLogo|showTitle</item>
<item name="android:titleTextStyle">#style/Theme.SexyApp.ActionBar.TextAppearance</item>
<item name="titleTextStyle">#style/Theme.SexyApp.ActionBar.TextAppearance</item>
</style>
<style name="Theme.SexyApp.ActionBar.TextAppearance" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#333333</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowDy">1</item>
</style>
<style name="Theme.SexyApp.ActionBar.MenuTextStyle" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">13dp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#333333</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowDy">1</item>
</style>
To change the menu item text color, you need to add the actionMenuTextColor item to your theme style as in the code below:
<style name="ThemeName" parent="#style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
To update the menu item text appearance (color, size, style) you need to make changes at two different places. The following answer is for sherlock.actionbar
1: In your themes.xml file add following lines:
<style name="Theme.Mytheme" parent="#style/Theme.Sherlock">
<item name="android:actionMenuTextAppearance">#style/CustomMenuItem</item> // define custom style in the style.xml file.
<item name="actionMenuTextColor">#color/mycolor</item>
<item name="android:actionMenuTextColor">#color/mycolor</item>
2: In your styles.xml
<style name="CustomMenuItem" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textStyle">normal</item>
<item name="android:textSize">15sp</item>
<item name="android:textAllCaps">false</item>
</style>