簡體   English   中英

如何刪除操作欄右上角的設置圖標(溢出菜單)?

[英]How do I remove settings icon (overflow menu) on top-right of action bar?

如何從操作欄的右上角刪除設置圖標? 當我在我的實際三星galaxy s3手機上模仿時,它不存在,但是,當我在Nexus 7的AVD上模擬時,它出現了。 這是我的菜單的代碼:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/main_menu_actionbutton"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:title="@string/Menu"/>
</menu>

如果你的意思是三個點,那就叫做溢出菜單。 它存在於沒有硬件菜單按鈕的設備上 - 你的Galaxy S3有,而Nexus 7卻沒有。 所以在你的S3上你按下菜單按鈕並在底部彈出窗口,但是在Nexus上你按下3個點並從操作欄中獲得溢出彈出窗口。 如果不存在,您將如何訪問溢出項?

如果您只是想完全刪除它,只需刪除您發布的menu.xml的第一個<item />條目。

“MainActivity”java類中有兩種方法。 它們被稱為onCreateOptionsMenu和onOptionsItemSelected。 當您使用默認設置在項目中創建活動時,這些通常由Eclipse(如Eclipse)添加。 方法如下所示。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.settings, 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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

這些方法創建菜單項並插入代碼,以便在單擊其中一個菜單項時執行操作。 只需刪除或注釋掉這兩種方法,您就會發現菜單按鈕會消失。 如果您想要菜單項或菜單,XML仍然可以使用它們。

作為android:showAsAction為以下項目設置為永遠不會這個項目成為溢出菜單的一部分。 將此設置為always或ifroom r刪除此項目,它將起作用

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

暫無
暫無

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

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