set actionbar icon height to match actionbar height

android, android-actionbar

Solution

The reason your icon doesn't fill the `ActionBar` is due to how the `ActionMenuItemView` measures the icon.

The `ActionMenuItemView` invokes a maximum size of `32dp` when it sets the bounds for your icon

So, it makes so difference how large your image is, the system will always resize it.

any idea how i can get the check to fill the actionbar?

You should use a action layout for your `MenuItem`, a check mark icon with no background, and change the background color of the action layout parent as you see fit. Here's an 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 to make sure your `MenuItem` is accessible. Normally when you long press an item in the `ActionBar` a short `Toast` will display the content description for you, but when you're using a custom `MenuItem` it's up to you to implement this pattern. An easy way to do this is by using Roman Nurik's CheatSheet. If you're unsure how to use it, you should refer to my answer here that goes into much more detail on creating custom `MenuItem` layouts.

Alternatively

If you want to use that background color for every `MenuItem` you have, you could create a custom style and apply it using the `android:actionButtonStyle` attribute. Here's an 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

Problem

see the problem here, the grey checkbox leaves room from the top and bottom of the 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 the item like 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 is the @drawable/check being used. any idea how i can get the check to fill the actionbar?

Original source