Menu items should specify a title(解决方法)

来源:互联网 发布:淘宝手机端图片模糊 编辑:程序博客网 时间:2024/06/16 11:54

Just a wrong XML namespace! Try with:

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

And as G.T. suggested you should consider using appcompat on the showAsAction property (only needed if you want to support API < 11):

<menu xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto">    <item        android:id="@+id/item1"        android:icon="@drawable/ic_launcher"        app:showAsAction="ifRoom|withText"        android:title="@string/Add_New" /></menu>

Note:

The appcompat library is compatible with some old Android versions (API 7+) that can't handle the showAsAction property because they don't have the ActionBar (API < 11).

shareimprove this answer
 
 
Thanks a million, worked like a charm! – user3375184 Jan 28 '15 at 14:59
up vote0down vote

Try this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"><item android:id="@+id/item1" android:icon="@drawable/ic_launcher" android:title="@string/Add_New" app:showAsAction="ifRoom|withText"></item></menu>

It works for me perfectly.

shareimprove this answer
 
 
I can't see what you added to my answer. – Gorcyn Jan 27 '15 at 15:19


http://stackoverflow.com/questions/28157511/android-studio-menu-item

0 0
原创粉丝点击