Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show menu item under overflow icon in android api 8+

How I can force menu item to show under overflow icon. I am providing app support from api level 8 and above. for now it is showing as actionview . My menuLayout is as follows.

 //main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >

<item
    android:id="@+id/action_menu_setting"
    android:title="@string/menuItemSetting"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/action_signout"
    android:title="@string/menuItemLogout"
    app:showAsAction="ifRoom"/>
 </menu>     

in Java class

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
    }

I have tried with other options of showAsAction but none of them worked. Please suggest me how I can show above two menu itme under overflow icon(when i click on over these two will appearer as actionlist.)

like image 479
maddy d Avatar asked Mar 19 '26 08:03

maddy d


1 Answers

layout for custom action bar

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="@drawable/header"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvActionBarTitle"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:gravity="center"
        android:textColor="#FFFFFF"
        android:textSize="30sp" />

    <Button.../>
<!--     your code for button -->
</LinearLayout>

You can call below function in onCreate and define button in this function as I have defined appName text view and its OnClick event

 private void createCutomActionBarTitle()
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            {
                this.getActionBar().setHomeButtonEnabled(true);
            }
            this.getActionBar().setDisplayShowCustomEnabled(true);
            this.getActionBar().setDisplayShowTitleEnabled(false);
            this.getActionBar().setBackgroundDrawable(drawable);
            this.getActionBar().setIcon(logo);
            LayoutInflater inflator = LayoutInflater.from(this);
            View v = inflator.inflate(R.layout.custom_action_bar, null);

            ((TextView) v.findViewById(R.id.tvActionBarTitle)).setText(Global.ACTIVITY_NAME);

            this.getActionBar().setCustomView(v);
        }

Hope this will be useful for you :) But clicking physical button of device will not trigger this button you have to look for it, as I don't have any idea about it

like image 131
Android Noob Avatar answered Mar 21 '26 21:03

Android Noob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!