2
votes

I have a menu item in action bar. Which always looks small as in below image.

enter image description here

I want its size to be approx. double of this. I have put different sized icons in mdpi, hdpi, xhdpi folders. Thus, it is not a dpi related problem.

I have this issue in HTC One and emulator which is xhdpi. I tried enlarging icon in xhdpi folder and tested in emulator, but no change in its size in action bar. For micromax canvas2(hdpi) it works fine.

Is there any way to set menu item's size to fix height and width? Or any other workaround?

4
can you put your xml code?Sushil
@Sushil xml for menu item? OR whole layout? To make it more clear, this is the problem for all screen that has menu item in action bar. SO may be problem with menu item code only.Geek
may be you can use a custom title bar and can control the size of menu items. In that case dont use menu itema at all. I have posted a custom titlebar code below.Sushil
you could do something like this: set the menu item value or drawable, and then get the density dpi value and check if its xhdpi if so, set the width n the heightRat-a-tat-a-tat Ratatouille
@DharaShah As mentioned in question, I did not find any way to set the size for menu item.Geek

4 Answers

3
votes

I have the same issue, and so far I have not found a solution. It is HTC specific and I observed this behavior on an HTC One X.

Their Sense framework forces a square menu icon, so it narrows your view. As a workaround, I didn't use the menu items api, I created a custom view for the action bar and aligned my imageview to the right (while preserving the title and home icon) using this answer: SherlockActionBar: How to adjust CustomView against actionBar

1
votes

May be you can use custom title bar:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@drawable/action_bar"
    android:orientation="horizontal" >

<LinearLayout
    android:id="@+id/slidingmenu"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" 
    android:paddingLeft="20dip"
    android:layout_centerInParent="true" 
    android:layout_alignParentLeft="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/slidingmenu_selector" 
        android:duplicateParentState="true" />
 </LinearLayout>


<TextView
        android:id="@+id/myheading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="#000000"
        android:textStyle="bold"
        android:textSize="23dp" />

<LinearLayout
    android:id="@+id/homemenu"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" 
    android:paddingRight="20dip"
    android:layout_centerInParent="true" 
    android:layout_alignParentRight="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/homemenu_selector" 
        android:duplicateParentState="true" />
 </LinearLayout>


</RelativeLayout>
1
votes

Put the image in drawable-nodpi folder

0
votes

I solved this issue by using custom view for menuitem.

Layout for menu item :

    <ImageButton
        android:id="@+id/first_menu_item"
        android:layout_width="56dp"
        android:layout_height="33dp"
        android:layout_gravity="center"
        android:contentDescription=""
        android:background="@drawable/menu_item_background"
        android:gravity="center" />

</LinearLayout>

Set custom view for actionbar in activity :

// Set custom menu items for action bar
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                            | Gravity.CENTER_VERTICAL);   // Set Layout Parameters
lp.setMargins(5, 5, 10, 5); // Left, top, right, bottom margins
View view = LayoutInflater.from(this).inflate(
                    R.layout.actionbar_menu_item, null);
ImageButton menuItem = (ImageButton) view
                    .findViewById(R.id.first_menu_item);
menuItem.setImageDrawable(getResources().getDrawable(
                    R.drawable.edit_button));
menuItem.setOnClickListener(this);
actionBar.setCustomView(view, lp);
actionBar.setDisplayShowCustomEnabled(true);