I have searched around the forum, and I still do not know what's the problem. Action bar Icons dont show up. Actually, Im following a book.. and I did all what in the book is to let the icons appear. I hope I get some answers. Thanks a lot.
<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.hfad.bitsandpizzas.MainActivity"> <item android:id="@+id/action_create_order" android:title="@string/action_create_order" android:icon="@drawable/ic_action_create_order" android:orderInCategory="1" app:showAsAction="ifRoom" /> <item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" /> </menu>
package com.hfad.bitsandpizzas; import android.app.Activity; import android.os.Bundle; import android.view.Menu; public class MainActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } // Implementing this method adds any items in the menu resource file to the action bar. @Override public boolean onCreateOptionsMenu(Menu menu){ getMenuInflater().inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } }
You can't show icons in overflow menu. By default all menu items displayed in overflow menu are displaying without icons, only text.
Change your menu to:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_test"
app:showAsAction="always"
android:icon="@drawable/ic_launcher"
android:title="@string/action_settings"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
orderInCategory should be equal to 100 to make its icon visible...
OK people, I have continued reading the book.. it is writing that : The action item may appear in the overflow instead. This is due to a bug in dome revisions of the v7 appcompact library. If this is a problem in your app, report it in Google.
Thanks a lot Guys.
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.