insert a custom style inside two different theme - android

I want to add a custom style that is for example purple in one theme and red in one other theme.
<style name="subtitle_layout" parent="#android:style/Theme.Holo.Light">
<item name="android:background">#color/purple</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40sp</item>
</style>
<style name="subtitle_layout2" parent="#android:style/Theme.Holo.Light">
<item name="android:background">#color/black</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">80sp</item>
</style>
<style name="Theme1" parent="android:Theme.Holo.Light">
<item name="android:textColor">#color/black</item>
<item name="#style/subtitle_layout">#style/subtitle_layout</item>
</style>
<style name="Theme2" parent="android:Theme.Holo.Light">
<item name="android:textColor">#color/white</item>
<item name="#style/subtitle_layout">#style/subtitle_layout2</item>
</style>
The change of theme works because i see the change of text color, but instead of android:textColor i would like to put a style instead. But it doesn't work.

I guess you are trying to inherit existing styles to your theme, am I right? You can just set the style as your parent theme:
<style name="Theme1" parent="#style/subtitle_layout">
<item name="android:textColor">#color/black</item>
</style>

Related

colorAccent in Holo Theme

I used this to change the accent color in EditText in the Material Theme:
<style name="AppThemeSub" parent="#android:style/Theme.Material.Light">
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorAccent">#color/colorPrimary</item>
</style>
And this to change the ProgressBar color:
<style name="AppThemeWeb" parent="#android:style/Theme.Material.Light">
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorAccent">#color/white</item>
</style>
How I can use this in Holo Theme?
PS: I used the indeterminateDrawable in the layout of ProgressBar and not work with Holo Theme devices.
You have to use the AppCompat theme like this will behave as holo and you can set all material properties here in your value's direcotry style.xml. I have used this theme.
//My Customized Theme
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/myPrimaryColor</item>
<item name="colorPrimaryDark">#color/myPrimaryDarkColor</item>
<item name="colorAccent">#color/myAccentColor</item>
<item name="android:textColorPrimary">#color/myPrimaryTextColor</item>
<item name="android:textColorSecondary">#color/mySecondaryTextColor</item>
<item name="android:actionBarDivider">#color/myDividerColor</item>
<item name="android:windowActionModeOverlay">true</item>
</style>

buttonStyle not working for 22.1.1

I´m Using com.android.support:appcompat-v7:22.1.1
This attribute android:buttonStyle is not setting that style for every button, I need to set android:theme="#style/AppTheme.Button" manually on each button.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/AppTheme.Button</item>
</style>
What do I need to do to set a general style for it?
Use buttonStyle insteadof android:buttonStyle in your theme
Similar to #danielgomezrico answer but without having two style files:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- android:buttonStyle for v21+ and buttonStyle for the rest -->
<item name="buttonStyle">#style/MyCustomButton</item>
<item name="android:buttonStyle">#style/MyCustomButton</item>
<item name="colorButtonNormal">#color/my_color_accent</item>
</style>
<style name="MyCustomButton" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#ffffff</item>
</style>
I ended up setting background color with colorButtonNormal attribute and other style attributes with buttonStyle.
values/style.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/my_color_primary</item>
<item name="colorPrimaryDark">#color/my_color_primary_dark</item>
<item name="colorAccent">#color/my_color_accent</item>
</style>
<style name="AppTheme.Base">
<item name="colorButtonNormal">#color/my_color_accent</item>
<item name="buttonStyle">#style/Button</item>
</style>
<style name="Button" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#color/my_color_white</item>
</style>
values-v21/style.xml
<style name="AppTheme.Base">
<item name="android:colorButtonNormal">#color/my_color_accent</item>
<item name="android:buttonStyle">#style/Button</item>
</style>
And then all the buttons have the background/text color I wanted without setting style on each one.

AppCompat 21: name = colorPrimary not working together with name = actionBarStyle

When i'm using the item actionBarStyle, colorPrimary doesn't set the color to red.
If i delete the item actionBarStyle, it works. How can i change my code to display the color?
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyStyledActionBar</item>
<item name="colorPrimary">#color/red</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
</resources>
The root of Widget.AppCompat.Light.ActionBar is Base.Widget.AppCompat.ActionBar, which doesn't apply a background attribute.
<style name="Base.Widget.AppCompat.ActionBar" parent="">
...
<item name="background">#null</item>
<item name="backgroundStacked">#null</item>
<item name="backgroundSplit">#null</item>
...
</style>
Instead your parent should be Widget.AppCompat.Light.ActionBar.Solid, so that you'll inherit the attributes from Base.Widget.AppCompat.Light.ActionBar.Solid, which applies the background attribute.
<style name="Base.Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">?attr/colorPrimary</item>
<item name="backgroundStacked">?attr/colorPrimary</item>
<item name="backgroundSplit">?attr/colorPrimary</item>
</style>
Alternatively, you could just apply the background attribute yourself.
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="background">?attr/colorPrimary</item>
</style>

Android Actionbar navigation spinner text color

I am able to change the background of the navigation spinner:
<style name="MyTheme" parent="android:style/Theme.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionDropDownStyle">#style/MyDropDownNav</item>
</style>
<style name="MyDropDownNav" parent="android:style/Widget.Spinner">
<item name="android:background">#drawable/spinner_white</item>
<item name="android:textColor">#color/red</item>
</style>
Nevertheless the textColor is not changed. I also tried other ways to change the textColor:
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">?color_actionbar</item>
<item name="android:titleTextStyle">#style/myTheme.ActionBar.Text</item>
</style>
<style name="myTheme.ActionBar.Text" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/violet</item>
</style>
Any other idea?
I was looking for the same answer but didn't find anything, so I tried this solution. I works for me at least.
In the themes file, you can set the style for the spinnerDropdownItemStyle:
<style name="YourTheme" parent="YourParentTheme">
<item name="android:spinnerDropDownItemStyle">#style/YourCustomDropDownItemStyle</item>
</style>
Now, set the textappearance for your style:
<style name="YourCustomDropDownItemStyle" parent="#android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textAppearance">#style/YourCustomDropDownItemTextStyle</item>
</style>
And in your custom textappearance you can set the text details:
<style name="YourCustomDropDownItemTextStyle" parent="#android:style/Widget">
<item name="android:textColor">#color/white</item>
<!-- Here you can set the color and other text attributes -->
</style>
Hope this helps!

ActionBarSherlock - How to set the padding of each actionbar's icon?

How can I make the icons of the actionbar using ActionBarSherlock closer or further away from each other? Something like android:layout_marginLeftor android:paddingRight?
If I just add the icons on the actionbar they are further away compare to the screenshot of Soundhound below:
my themes.xml:
<style name="Theme.AstraTheme_Purple" parent="#style/Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.AstraTheme_Purple.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.AstraTheme_Purple.ActionBar</item>
<item name="actionButtonStyle">#style/Widget.AstraTheme_Purple.ActionButton</item>
<item name="android:actionButtonStyle">#style/Widget.AstraTheme_Purple.ActionButton</item>
</style>
<style name="Widget.AstraTheme_Purple.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#drawable/purple_bar</item>
<item name="background">#drawable/purple_bar</item>
</style>
<style name="Widget.AstraTheme_Purple.ActionButton" parent="Widget.Sherlock.ActionButton">
<item name="android:minWidth">50dip</item>
</style>
<style name="AppTheme" parent="Theme.Sherlock">
<item name="actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionButtonStyle" parent="Widget.Sherlock.ActionButton">
<item name="android:minWidth">32dip</item>
<item name="android:padding">0dip</item>
</style>
The default value of android:minWidth for the ActionBar buttons is 56dip.
Don't forget to set #style/AppTheme as the Activity's theme.

Categories

Resources