簡體   English   中英

溢出菜單不顯示

[英]Overflow Menu doesn't show

我的應用程序有問題...溢出菜單不可見! 我可以物理點擊手機的右上角,顯示菜單項,但不顯示三個點。

這是我的xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.android.example.MainActivity">

    <item
        android:orderInCategory="1"
        android:id="@+id/ic_home"
        android:title="Home"
        android:icon="@drawable/ic_home"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="2"
        android:id="@+id/ic_chat"
        android:title="Forum"
        android:icon="@drawable/ic_chat"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="3"
        android:id="@+id/ic_videos"
        android:icon="@drawable/ic_videos"
        android:title="Videos"
        app:showAsAction="withText"
        />

    <item
        android:orderInCategory="4"
        android:icon="@drawable/ic_timeline"
        android:id="@+id/ic_timeline"
        android:title="Timeline"
        app:showAsAction="withText"
        />

    <item
        android:icon="@drawable/ic_phone"
        android:id="@+id/ic_call"
        android:orderInCategory="5"
        android:title="Call"
        app:showAsAction="withText"
        />   

</menu>

Java代碼:

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    return super.onOptionsItemSelected(item);
}

我在StackOverflow上嘗試了其他解決方案,但似乎都沒有用。 我嘗試在2個手機上運行該應用程序,兩個手機的Android版本均> 4.4。

更新:我嘗試將導航抽屜添加到應用程序。 再次,當我點擊應該有抽屜按鈕的一側時,菜單會出現,但是按鈕不可見...

更新2:我嘗試更改style.xml中的主題設置。 當我將windowActionBar設置為true而不是false並將windowNoTitle設置為false而不是true時,將同時顯示抽屜和溢出菜單。 但是,我的工具欄會像這樣在操作欄下方顯示。

如何將菜單按鈕添加到實際的(白色)工具欄?

提前致謝。

您是否設置了toolbar

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

查看此答案以獲取完整說明。

刪除onCreateOptionsMenu和onOptionsItemSelected並像這樣使用它

 Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.main_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override 
        public boolean onMenuItemClick(MenuItem item) {
            return false;
        }
    });

或者,如果您不是處於活躍狀態,則必須在onCreateView中添加此行代碼

         setHasOptionsMenu(true);

好的,我找到了答案:

我再次獲得了默認操作欄,然后為自定義操作欄創建了布局資源文件。

我在自定義操作欄文件中添加了所需欄的設計/規格,然后將操作欄設置為自定義操作欄文件。

全部解決了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM