简体   繁体   中英

ActionBar Not Showing Icons, Android Studio

I recently moved from eclipse to android studio. while importing my project to android studio, i faced a problem with action bar icons not being displayed when running on my galaxy s3.

this is the xml code

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

    <item
        android:id="@+id/menu_item_share"
        app:showAsAction="ifRoom"
        android:icon="@drawable/ic_action_share"
        android:title="@string/Share"/>

    <item
        android:id="@+id/ShopCart"
        android:icon="@drawable/shopping"
        app:showAsAction="ifRoom"
        android:title="@string/MyCart"/>

    <item
        android:id="@+id/GoHome"
        android:icon="@drawable/ic_home1"
        app:showAsAction="ifRoom"
        android:title="@string/nowhome"/>

</menu> 

when using the preview option in the android studio, i can see those 3 item displayed on the virtual preview device.

在此处输入图片说明

this is the java part of the code, in this code i made a Toast to see if it gets processed and it did .

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_LONG).show();
        return true;
    }

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // if nav drawer is opened, hide the action items
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        //menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

note: this code as it is works fine on eclipse, when i imported the project into android studio, the action bar icons stopped showing .

I also have this problem. I just ignore Android Studio's red line and keep it as android:showAsAction="ifRoom". It works for me.

Try replace this:

app:showAsAction="ifRoom"

with:

android:showAsAction="ifRoom"

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