ActionBar with AppCompat actionBarItemBackground not working - android

I am trying to change the color of an item when it pressed. I used the actionBarItemBackground item in the action bar style, but nothing happens.. The color not changed...
Here my code:
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/actionbar_background</item>
<item name="titleTextStyle">#style/ActionBarStyle.Title</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>
And the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/pressed_item" android:state_focused="true"/>
<item android:drawable="#drawable/pressed_item" android:state_pressed="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>
And the drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#FF0000"/>
</shape>
What is worng? Someone?

actionBarItemBackground isn't inherit of Widget.ActionBar. You should be placing it in your root theme, wherever you apply your ActionBarStyle, but not in your ActionBarStyle. So, something like:
<style name="Your.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>

Related

android:theme="#style/..." doenst take background

I got the following background for an edit text:
edit_text_rounded_white.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#66c6c6c6"/>
<stroke android:width="0.1dp"
android:color="#66c6c6c6"/>
<corners android:radius="40dp"/>
</shape>
</item>
</selector>
in my styles.xml I define the following:
<style name="editText">
<item name="android:background">#drawable/edit_text_rounded_white</item>
<item name="android:drawablePadding">5dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:textCursorDrawable">#drawable/edit_text_cursor</item>
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="colorControlActivated">#color/transparentWhite50</item>
</style>
When I set the style via: style="#style/editText" for my editTexts it takes the background but doesnt take the colorControl I set. When I set the style via android:theme="#style/editText" it takes the colorControls but doesnt show the background image. I already tried src and windowBackground instead of background in the style file.
Any ideas how achieve both? Showing background and the colorControls?
Split your style into two:
<style name="editTextStyle">
<item name="android:background">#drawable/edit_text_rounded_white</item>
<item name="android:drawablePadding">5dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:textCursorDrawable">#drawable/edit_text_cursor</item>
</style>
<style name="editTextTheme">
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="colorControlActivated">#color/transparentWhite50</item>
</style>
And then apply both to your view:
<EditText
...
android:theme="#style/editTextTheme"
style="#style/editTextStyle"/>

No Ripple Effect With SelectableItemBackground

I'm trying to implement material design to legacy code.
I want a button to have a ripple effect on click but it shows nothing.
I'm using default ?android:attr/selectableItemBackground.
this is button xml:
<Button
android:text="Wandio"
android:padding="10dp"
android:textColor="#ffffff"
android:background="?android:attr/selectableItemBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/wandio_link" />
style in values folder:
<resources>
<color name="main_green">#45bb61</color>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#909CD4</item>
<item name="colorPrimaryDark">#D490CA</item>
<item name="colorAccent">#FFFFFF</item>
<item name="android:imageButtonStyle">#style/ImageButtonStyle</item>
<item name="android:windowBackground">#color/main_green</item>
</style>
<style name="ImageButtonStyle">
<item name="android:background">#android:color/transparent</item>
</style>
</resources>
style in values-v21 folder:
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:imageButtonStyle">#style/StyleApi21</item>
<item name="android:buttonStyle">#style/StyleApi21</item>
</style>
<style name="StyleApi21">
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
</style>
Never had this problem before. Can't find what I'm missing.
Any suggestions?
I tryed the same thing and I have used this in my custom button xml:
<item ><ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="#android:id/mask">
<shape android:shape="oval">
<solid android:color="#FFBB00" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#color/colorAccent" />
</shape>
</item>
</ripple>
Here is my another xml for older devices:
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/fab_selected" android:state_selected="true"/>
<item android:drawable="#drawable/fab_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/fab_normal"/>
</selector>
</item>
These drawable files are just different colors of the button.

Android TabBar Style not scaling to full screen

This is my current TabBar Style
<style name="SM5Theme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/SM5Theme.ActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/SM5Theme.ActionBarTabBarStyle</item>
<item name="android:actionBarTabTextStyle">#style/SM5Theme.ActionBarTabTextStyle</item>
</style>
<style name="SM5Theme.ActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/tab_bar_background</item>
<item name="android:gravity">center</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:showDividers">middle</item>
<item name="android:textColor">#color/tab_highlight</item>
</style>
<style name="SM5Theme.ActionBarTabTextStyle" parent="#android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:textColor">#color/tab_textcolor</item>
</style>
<style name="SM5Theme.ActionBarTabBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
</style>
TabBarBackground:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="#drawable/tab_bar_background_non_selected"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="#drawable/tab_bar_background_selected"/>
<item android:state_selected="false" android:state_pressed="true" android:drawable="#color/tab_highlight"/>
<item android:state_selected="true" android:state_pressed="true" android:drawable="#drawable/tab_bar_background_selected_pressed"/>
</selector>
tab_bar_background_selected:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-3dp" android:left="-3dp" android:right="-3dp">
<shape android:shape="rectangle">
<stroke android:color="#color/tab_bottom_bar" android:width="3dp"/>
<solid android:color="#color/tab_background_selected"/>
</shape>
</item>
</layer-list>
This works satisfactory on generating the Tab Theme and underline color. However, the problem is it's doesn't scale all the way.
How can I solve this? I don't want to use sherlock or the android theme generator.

How to change selected tab Color or Font color for ActionbarTab?

I am using xml to change background of selected tab using Actionbar Tab with view pager
code is below,
style.xml
<!-- Custom theme. -->
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:windowActionBar">true</item>
<item name="android:actionBarSize">30dp</item>
<item name="android:icon">#drawable/logo</item>
<item name="android:actionBarTabTextStyle">#style/Widget.Holo.TabWidget</item>
<!-- <item name="android:actionBarTabTextStyle">#style/customTabBar</item> -->
</style>
<style name="Widget.Holo.TabWidget" parent="android:style/Widget.TabWidget">
<item name="android:tabStripLeft">#null</item>
<item name="android:tabStripRight">#null</item>
<item name="android:tabStripEnabled">true</item>
<!-- <item name="android:divider">#android:attr/dividerVertical</item> -->
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">8dip</item>
<item name="android:divider">#android:attr/dividerVertical</item>
<item name="android:dividerHeight">10dp</item>
<item name="android:measureWithLargestChild">true</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/tab_bg_selector</item>
</style>
tab_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Active tab -->
<item android:drawable="#drawable/tab_bg_selected" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Inactive tab
<item android:drawable="#drawable/tab_bg_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
-->
<item android:drawable="#android:color/transparent" android:state_pressed="true"/>
<!-- Selected tab (using d-pad) -->
<item android:drawable="#android:color/transparent" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
tab_bg_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerColor="#7F7F7F"
android:endColor="#696969"
android:startColor="#A8A8A8" />
</shape>
It shows me changed color but color is changes for text background only I want to change for whole Tab selected
See below image,
These custom styles work fine for me
<style name="MyActionBarTabStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:tabStripEnabled">false</item>
<item name="android:footerDividersEnabled">false</item>
<item name="android:background">#drawable/tab_selector</item>
<item name="background">#drawable/tab_selector</item>
</style>
And
<style name="MyActionBarTabTextStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabText">
<item name="android:textColor">#color/tab_text_color</item>
<item name="android:textSize">12sp</item>
<item name="android:gravity">fill_horizontal</item>
</style>
I hope it works fine for u as well
Take a look to this: Styling Tabs

how to override pressed state color in sherlock action bar?

I implemented sherlock actionbar in my app which has dark green action bar ..
#008000. when i press the action bar button it turns out ics blue (default) color...how to turns out green when i press action bar button?.
IN themes.xml i am using this.
<resources>
<style name="Theme.Styled" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="actionBarItemBackground">#drawable/selector</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#008000</item>
<item name="android:background">#008000</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
</style>
in drawable selector.xml
<item android:state_pressed="true" android:drawable="#drawable/pressed" />
<item android:state_focused="true" android:drawable="#drawable/focused" />
<item android:drawable="#android:color/transparent" />
in drawable pressed.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#690"></solid>
</shape>
add this in your style
<item name="android:actionBarItemBackground">#drawable/selector</item>

Categories

Resources