简体   繁体   English

每当我尝试向操作栏添加按钮时,这些项目都会添加到溢出菜单下

[英]Whenever I try to add a button to my actionbar, the items are added under the overflow menu

I am trying to add a simple button to my action bar, but when I try to use the following code, the items are added as items under the overflow menu, not on the actionbar itself. 我试图在操作栏上添加一个简单的按钮,但是当我尝试使用以下代码时,这些项将作为项添加到溢出菜单下,而不是在操作栏本身上。 Any help would be appreciated, 任何帮助,将不胜感激,

Jacob 雅各布

Here is my Java: 这是我的Java:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_review, menu);


    return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case android.R.id.home:

            super.onBackPressed();
            return true;



        default:
            return super.onOptionsItemSelected(item);

    }
}

and my XML: 和我的XML:

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


    <item android:id="@+id/seda"
        android:icon="@drawable/redpinreal"
        android:title="Hello Worldh"
        android:showAsAction="withText|always"/>

</menu>    

I also have this enabled: 我也启用了此功能:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Part of your code ( android:showAsAction , instead of yourapp:showAsAction ) is attempting to use the native action bar. 您代码的一部分( android:showAsAction ,而不是yourapp:showAsAction )正在尝试使用本机操作栏。 Part of your code ( getSupportActionBar() , instead of getActionBar() ) is attempting to use the appcompat-v7 action bar backport. 您的部分代码( getSupportActionBar()而不是getActionBar() )正在尝试使用appcompat-v7操作栏回传。 Choose one and stick with it. 选择一个并坚持下去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM