Android support action bar not showing overflow me

2019-06-18 18:42发布

My android app supports 2.2 and higher. I'm using the appcompat support library for the action bar, so it should only show if there are things that don't fit. I want my action bar to support the overflow button (the three vertical squares) that reveals a menu with the other items when clicked.

In my menu file, I have three items set up. However on the app I only see two of them, and the overflow button is not showing as well.

activity_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:sord.ids_connect="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_settings"
        android:icon="@drawable/checkbox"
        android:title="@string/action_settings"
        sord.ids_connect:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_settings2"
        android:icon="@drawable/checkbox_checked"
        android:title="@string/action_settings"
        sord.ids_connect:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_settings3"
        android:icon="@drawable/ic_launcher"
        android:title="@string/action_settings"
        sord.ids_connect:showAsAction="ifRoom" />  

</menu>

java file

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class Activity_Menu extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_menu, menu);
        //return true;
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                super.onBackPressed();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

manifest

    <activity
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
        android:name="sord.ids_connect.Activity_Menu"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_menu" >
    </activity>

7条回答
在下西门庆
2楼-- · 2019-06-18 19:45

I had the same problem. I solved it by:

1) commenting return true;

2) uncommenting return super.onKeyUp(keyCode, event);

in public boolean onKeyUp(int keyCode, KeyEvent event)

查看更多
登录 后发表回答