简体   繁体   中英

Disable collapse button in actionbar - Android

I have a problem with Button in Action Bar. So why i create Button in Action Bar it only collapse never show icon . This is my menu

<item
    android:id="@+id/action_name"
    android:icon="@drawable/icon_home"
    android:title="Home"
    app:showAsAction="ifRoom"
    android:orderInCategory="0"/>

And this is my screen: 在此处输入图片说明

try like,

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="schemas.android.com/apk/res/android"
      xmlns:app="schemas.android.com/apk/res-auto">
<item
    android:id="@+id/action_name"
    android:icon="@drawable/icon_home"
    android:title="Home"
    app:showAsAction="always"
    android:orderInCategory="1" /> </menu>

and

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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