I am creating an actionbar with custom looking buttons that I put in the icon section of menu.xml.
The problem is that, when I press them, I see both the selected version of the image of the button and the blue background of the holo theme.
This is my menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/current_position"
android:icon="#drawable/ab_location_layer"
android:menuCategory="container"
android:showAsAction="ifRoom"
android:title="Current position">
</item>
</menu>
The ab_location_layer is this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ab_location_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/ab_location" android:state_pressed="false"/>
</selector>
The ab_location_layer contains an image that is smaller than the actionBar.
How is possible to remove the blue background on actionbar? I am also using actionbarsherlock.
Thanks
I found the answer on ActionBarSherlock Mailing List:
you have to put this
<item name="android:selectableItemBackground">#null</item>
<item name="android:actionBarItemBackground">#null</item>
<item name="actionBarItemBackground">#null</item>
to your theme and not in ActionBar theme
Related
I'm building an android app with several menu on actionbar. And here is the menu.xml.
<menu>
<item
android:id="#+id/menu_comment"
android:icon="#drawable/gsm_comment_selector"
android:title="#string/COACH_COMMENT"
app:showAsAction="always"/>
<item
android:id="#+id/menu_more"
android:icon="#drawable/menu_more_selector"
android:title="#string/MORE"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menu_share"
android:icon="#drawable/menu_share_selector"
android:title="#string/SHARE"/>
<item
android:id="#+id/menu_help"
android:icon="#drawable/menu_help_selector"
android:title="#string/HELP"/>
</menu>
</item>
</menu>
And this is what a XXX_selector looks like. It contains a drawable and a template_selector(a color state list) so I can change the icon color when I click it.
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_more_vert_white_24dp"
android:tint="#color/template_selector"/>
The result is that when pressing menu_comment and menu_more, its icon color are changed. But menu_share and menu_help are not.
So what should I do to fix it?
Thanks
You should be able to do something like following (called from onCreateOptionsMenu)
Drawable drawable = DrawableCompat.wrap(menuItem.getIcon());
DrawableCompat.setTint(drawable.mutate(), context.getResources().getColor(tint));
view.setIcon(drawable);
If I press a button in the action bar, then its background color is not what I want. The background color of my item doesn't respond to my click event. How can I change this and change the background color when it's pressed?
You need to declare android:actionBarItemBackground attribute which is a:
Custom item state list drawable background for action bar items.
Then, in your styles do as follows:
<style name="CustomStyle" parent="#style/Theme.Holo.Light" >
<item name="android:actionBarItemBackground">#drawable/ab_item_background</item>
<item name="actionBarItemBackground">#drawable/ab_item_background</item>
</style>
So, put your own drawable with a selector and every state (pressed, focused, disabled, etc) to have the expected background. For example, the drawable ab_item_background.xml declared above might be like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime">
<!-- focused/pressed: color=red -->
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="#color/red" />
<!-- pressed: color=red -->
<item
android:state_pressed="true"
android:drawable="#color/red" />
<!-- normal: color=transparent -->
<item
android:drawable="#android:color/transparent" />
</selector>
In Styling the Action Bar, you can find all the customization possibles and all the attributes to do so.
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0a0a0a")));
this might help
I have the following dropdown:
<style name="SpinnerDropdown" parent="android:style/Widget.ListView.DropDown">
<item name="android:background">#04384f</item>
<item name="android:divider">#000000</item>
<item name="android:dividerHeight">1dp</item>
</style>
I want to change the color of the currently pressed item. This color is currently orange (#feba21) and I want it to be something else. I haven't set it anywhere so I assume it's inherited from Widget.ListView.Dropdown
How can I change it, and more importantly where can I find Windget.ListView.Dropdown in the SDK so I can see what properties it has?
I tried adding the selector_spinner_option:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/bright_positive" />
<item android:drawable="#color/dimmer_positive" />
</selector>
as the background of SpinnerDropdown, but what it does is change all the other items when one item is pressed - while that item remains orange!!
Orange is not the background of dropdown item. It is a color of selector. It is easy to change it by the attribute listSelector
The following code will change orange to green
<style name="SpinnerDropdown" parent="android:style/Widget.ListView.DropDown">
<item name="android:background">#04384f</item>
<item name="android:divider">#000000</item>
<item name="android:listSelector">#00ff00</item>
<item name="android:dividerHeight">1dp</item>
</style>
Hope it help.
The "more" item will show on the ActionMode when there are more than 3 items, but it is automatically generated. I want change the background when I press it. What should I do?
I'm working on Android 4.0 API level 15.
I have solved this problem.
<style name="Theme.Seven" parent="android:Theme.Holo">
...
...
<item name="android:selectableItemBackground">#drawable/action_background</item>
</style>
action_background.xml as below:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime" >
<item android:state_pressed="true" android:drawable="#drawable/btn_dismiss_pressed" />
<item android:drawable="#android:color/transparent" />
</selector>
I've created custom ToggleButtons in Android and since all buttons inherit from the same xml I want to change how they act depending on state, so when the state is checked I want to change the shadow color but this does not seem to possible with the current SDK.
I've created an xml file which holds button_colors:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:color="#FFFFFF" />
<item
android:color="#000000" />
</selector>
But this only seems to work with text-color and not shadow color on the text.
Is there something I'm missing?
And rather not do this for every button manually in code since I want this to apply to every button in the app.
UPDATE EDIT:
My selector currently looks like this
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="#drawable/button_gradient_selected" />
<item
android:drawable="#drawable/button_gradient" />
</selector>
But as I mentioned to the commentator below I can't seem to change the style/text-color-shadow from here since it only can take in a drawable it seems.
When I try to put in a different style on the button in here it force closes or either does not change the style depending on state. When I only try to put in the style here and have the drawable be set in the style it force closes. Either way it does not work it seems.
Seems that the Android framework does not support this.
From TextView.java:
case com.android.internal.R.styleable.TextView_textColor:
textColor = a.getColorStateList(attr);
break;
case com.android.internal.R.styleable.TextView_shadowColor:
shadowcolor = a.getInt(attr, 0);
break;
They treat textColor and shadowColor differently.
Please refer to my solution on a different StackOverFlow question. I extended TextView to give a working solution here. (Replace TextView with Button)
This is the Selector file you have to implement:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/btn_toggle_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_toggle_on" />
</selector>
These are the picture tey used for the default ToggleButton:
btn_toggle_on and btn_toogle_off
You can have a selector for the shadow color like this: color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:color="#color/btn_text_on" />
<item
android:state_focused="true"
android:color="#color/btn_text_on" />
<item
android:color="#color/btn_text_off" />
</selector>
and then use this selector while styling your button in styles.xml like this:
<style name="ButtonStyle">
<item name="android:textColor">#FF383C48</item>
<item name="android:textSize">12sp</item>
<item name="android:shadowColor">#drawable/color_selector</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
<item name="android:typeface">sans</item>
<item name="android:textStyle">bold</item>
</style>