Set the height of the action bar icon to match the height of the action bar

see the problem here, a gray flag leaves the room above and below the action bar: small actionbar icon

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 as follows:

 getMenuInflater().inflate(R.menu.submit_action, menu); 

submit_action is as follows:

 <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 @ drawable / check.

enter image description here

Any idea how I can get a check to populate the action bar?

+6
source share
2 answers

The reason your icon doesn't fill the ActionBar is because the ActionMenuItemView measures the icon.

ActionMenuItemView calls a maximum size of 32dp when it sets the borders for your icon

So, it is so different from the size of your image, the system will always resize it.

Any idea how I can get a check to populate the action bar?

You should use the action layout for MenuItem , the checkmark icon without background and change the background color of the parent action layout as you see fit. Here is 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"/> 

Availability

It is important that your MenuItem is available. Usually, when you click an item in an ActionBar for a long time, a short Toast will display a description of the content for you, but when you use a custom MenuItem for you to implement this template. An easy way to do this is with the Roman Nurik CheatSheet . If you do not know how to use it, you should refer to my answer here , which contains more detailed information on creating custom MenuItem layouts.

As an alternative

If you want to use this background color for each MenuItem , you can create your own style and apply it using the android:actionButtonStyle . Here is an example of this:

Your style

 <style name="Your.ActionButton" parent="@android:style/Widget.Holo.Light.ActionButton"> <item name="android:background">#e8e8e8</item> </style> 

Your subject

 <style name="Your.Theme" parent="@android:style/Theme.Holo.Light"> <item name="android:actionButtonStyle">@style/Your.ActionButton</item> </style> 

results

Example

+4
source

Here is what I do with the icons in Android to get the dimensions right. You have an existing project with res / drawable folders. You must place the correct icon in the desired folder.

Start a new project wizard, and when you get to the launch icon, enter the icon you want to use in your existing project. complete the wizard. The wizard will make various icon sizes for you. Then I manually copy the icons from res / drawable-xdpi res / drawable-ldpi etc. To the appropriate folder in my existing project. Delete a new project is no longer required.

-1
source

All Articles