I have ActionBar Sherlockwith ViewPagerIndicatorlike here.
I'm trying to change ActionBarbackground but it does nothing.
Here is my code:
AndroidManifest.xml
<application
//...
android:theme="#style/StyledIndicators" >
styles_mystyle.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Mystyle" parent="#style/Theme.Sherlock.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_mystyle</item>
<item name="popupMenuStyle">#style/PopupMenu.Mystyle</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Mystyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Mystyle</item>
<item name="actionDropDownStyle">#style/DropDownNav.Mystyle</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Mystyle</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Mystyle</item>
<item name="actionModeBackground">#drawable/cab_background_top_mystyle</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_mystyle</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Mystyle</item>
</style>
<style name="ActionBar.Solid.Mystyle" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/background_actionbar</item>
<item name="background">#drawable/background_actionbar</item>
</style>
//more styles
<style name="StyledIndicators" parent="#style/Theme.Mystyle">
//some items for ViewPagerIndicator
</style>
<resources>
background_actionbar.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#DD84A4E8"
android:startColor="#7784A4E8" />
</shape>
Do you know where the problem is?
Related
I have defined two styles in Style.xml, I want to change the style programmatically for certain conditions, Min SDK version 21
<style name="CheckOutButtonStyle" parent="#style/Widget.AppCompat.Button.Colored">
<item name="android:layout_height">60dp</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">16sp</item>
<item name="android:padding">0dp</item>
<item name="android:textColor">#color/white_color</item>
<item name="android:layout_margin">#dimen/general_spacing</item>
</style>
<style name="ScanNextItemSecondaryButtonStyle" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:stateListAnimator">#null
</item> <!-- remove the shadow, per UI request -->
<item name="android:textSize">16sp</item>
<item name="android:padding">0dp</item>
<item name="android:minHeight">0dp</item>
<item name="android:minWidth">0dp</item>
<item name="android:background">#null</item>
<item name="android:textColor">#color/colorSecondaryAccent</item>
<item name="android:layout_marginBottom">#dimen/general_spacing</item>
</style
1. Create xml in drawable.
\res\drawable\back_button_answer.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="10dip" />
<!-- background -->
<gradient
android:startColor="#D6D7D6"
android:centerColor="#E2E2E2"
android:centerY="0.75"
android:endColor="#D6D7D6"
android:angle="270"
/>
<stroke android:width="2dip" android:color="#fff"/>
</shape>
2. Button btn.setBackgroundResource(R.drawable.back_button_answer);
I implemented a shader in this way, the xml file is called horde_shader.xml, and looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="#color/bordeaux"
android:angle="270">
</gradient>
</shape>
I have also implemented the following themes, in the related style.xml file that looks like this:
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AllyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/royalBlue</item>
<item name="colorAccent">#color/royalBlue</item>
<item name="android:navigationBarColor">#color/royalBlue</item>
<item name="colorShader">#drawable/ally_shader</item>
<item name="imageFaction">#drawable/ally</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorHint">#android:color/white</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="HordeTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/bordeaux</item>
<item name="colorAccent">#color/bordeaux</item>
<item name="android:navigationBarColor">#color/bordeaux</item>
<item name="colorShader">#drawable/horde_shader</item>
<item name="imageFaction">#drawable/horde1</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="Theme">Theme</style>
<style name="AppTheme">AppTheme</style>
</resources>
I tried in an activity to set the background in this way:
<TextView
android:id="#+id/banner_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Esempio Titolo"
android:textAlignment="center"
android:fontFamily="serif"
android:textColor="#FFF"
android:paddingBottom="5dp"
android:background="?attr/colorShader"
android:layout_alignParentBottom="true"
android:textSize="17dp"/>
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.
I'm having a problem, I'm developing a app and I want to change background color of the buttons of the Action Bar. I have made follow it:
In my menu.xml, I have this code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".main" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_search"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="#string/action_search"/>
<item android:id="#+id/action_carrito"
android:title="#string/action_example"
android:icon="#drawable/ic_carrito"
app:showAsAction="always" />
</menu>
And my styles.xml, I have this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#android:color/white</item>
<item name="android:textSize">18sp</item>
</style>
<style name="MyActionButtonStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/darker_green</item>
</style>
</resources>
Both buttons catch this background color. But I only want to put it for the button with id is "#+id/action_carrito". I hope somebody can to help me. Thanks in advance.
What if you try to create a action_carrito_bg.xml which is a layer-list under your drawable folder, that looks like:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/darker_green"></solid>
</shape>
</item>
<item>
<bitmap android:src="#drawable/ic_carrito"/>
</item>
</layer-list>
Then remove MyActionButtonStyle from styles.xml, and set that drawable as icon of the menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".main" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_search"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="#string/action_search"/>
<item android:id="#+id/action_carrito"
android:title="#string/action_example"
android:icon="#drawable/action_carrito_bg"
app:showAsAction="always" />
</menu>
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>