菜单栏图标未显示 Eclipse Android
menu bar icons not shown Eclipse Android
显示了菜单栏,但我的图标没有显示在布局顶部。
菜单 xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_write"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_write"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_read"
android:title="@string/action_read"
android:showAsAction="never" />
</menu>
显示菜单:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return super.onCreateOptionsMenu(menu);
}
我在 Galaxy Note 3 上使用 4.4.2。我尝试了很多东西但没有任何效果(6 小时)。我正在使用 appcompat_v7.
延长:
public class myActivity extends ActionBarActivity
感谢任何帮助。
您必须使用自己的命名空间作为支持库定义的所有属性的前缀。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_write"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_read"
android:title="@string/action_read"
yourapp:showAsAction="never" />
</menu>
示例来自 Android 开发者网站:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Using XML attributes from the support library Notice that the
showAsAction attribute above uses a custom namespace defined in the
tag. This is necessary when using any XML attributes defined by
the support library, because these attributes do not exist in the
Android framework on older devices. So you must use your own namespace
as a prefix for all attributes defined by the support library.
显示了菜单栏,但我的图标没有显示在布局顶部。
菜单 xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_write"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_write"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_read"
android:title="@string/action_read"
android:showAsAction="never" />
</menu>
显示菜单:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return super.onCreateOptionsMenu(menu);
}
我在 Galaxy Note 3 上使用 4.4.2。我尝试了很多东西但没有任何效果(6 小时)。我正在使用 appcompat_v7.
延长:
public class myActivity extends ActionBarActivity
感谢任何帮助。
您必须使用自己的命名空间作为支持库定义的所有属性的前缀。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_write"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_read"
android:title="@string/action_read"
yourapp:showAsAction="never" />
</menu>
示例来自 Android 开发者网站:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Using XML attributes from the support library Notice that the showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library.