android - set actionbar icon height to match actionbar height -
see problem here, grey checkbox leaves room top , bottom of action bar:
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="customactionbartheme" parent="theme.base.appcompat.light"> <item name="android:windowcontentoverlay">@null</item> <item name="android:actionbuttonstyle">@style/actionbuttonstyle</item> </style> <!--<style name="actionbuttonstyle" parent="@android:style/widget.holo.light.actionbutton">--> <style name="actionbuttonstyle" > <item name="android:height">@dimen/abc_action_bar_default_height</item> <item name="android:layout_height">@dimen/abc_action_bar_default_height</item> </style>
i set item so:
getmenuinflater().inflate(r.menu.submit_action, menu);
submit_action looks like:
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_submit" android:icon="@drawable/check" app:showasaction="always" /> </menu>
and finally, attached @drawable/check being used.
any idea how can check fill actionbar?
the reason icon doesn't fill actionbar
due how actionmenuitemview
measures icon.
the actionmenuitemview
invokes maximum size of 32dp
when sets bounds icon
so, makes difference how large image is, system resize it.
any idea how can check fill actionbar?
you should use action layout menuitem
, check mark icon no background, , change background color of action layout parent see fit. here's example:
layout
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/actionbuttonstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#e8e8e8" android:clickable="true" android:contentdescription="@string/cd" > <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentdescription="@null" android:scaletype="centerinside" android:src="@drawable/ic_action_tick" /> </relativelayout>
menuitem
<item android:id="@+id/action_submit" android:actionlayout="@layout/your_action_layout" android:showasaction="always"/>
accessibility
it's important make sure menuitem
accessible. when long press item in actionbar
short toast
display content description you, when you're using custom menuitem
it's implement pattern. easy way using roman nurik's cheatsheet. if you're unsure how use it, should refer my answer here goes more detail on creating custom menuitem
layouts.
alternatively
if want use background color every menuitem
have, create custom style , apply using android:actionbuttonstyle
attribute. here's example of that:
your style
<style name="your.actionbutton" parent="@android:style/widget.holo.light.actionbutton"> <item name="android:background">#e8e8e8</item> </style>
your theme
<style name="your.theme" parent="@android:style/theme.holo.light"> <item name="android:actionbuttonstyle">@style/your.actionbutton</item> </style>
results
Comments
Post a Comment