我正在使用AppCompat将我的应用回溯到API7,但是在操作栏方面遇到了问题。
当我使用FragmentActivity
时,在我的手机上(API18)会显示操作栏,但是当我使用ActionBarActivity
时,它会在按下菜单按钮后显示为选项菜单。
在API7的模拟器上,操作栏始终显示为选项菜单。
有什么想法吗?
我正在使用AppCompat将我的应用回溯到API7,但是在操作栏方面遇到了问题。
当我使用FragmentActivity
时,在我的手机上(API18)会显示操作栏,但是当我使用ActionBarActivity
时,它会在按下菜单按钮后显示为选项菜单。
在API7的模拟器上,操作栏始终显示为选项菜单。
有什么想法吗?
像这样在您的菜单项中使用兼容名称空间:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_whatever"
android:icon="@drawable/ic_action_whatever"
android:title="@string/whatever"
compat:showAsAction="ifRoom" />
</menu>
always ,但我无法使按钮显示为操作项而不是溢出项。 我通过使用 Activity 而不是 ActionBarActivity 扩展我的活动来强制执行它。 根据这个答案,如果您不需要支持低于11的API级别,则可以接受此方法。
...扩展ActionBarActivity
:
...扩展Activity
:
我使用Doogee Valencia Y100Pro进行调试,但是菜单中的“三个小方块”不可见。当我将MainActivity扩展为android.support.v7.app.ActionBarActivity
时,我就可以在操作栏中获得文本/图标菜单了。接下来是screenshot和menu.xml。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_update"
android:icon="@drawable/ic_refresh"
android:title="@string/action_update"
app:showAsAction="always"/>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="ifRoom"/>
</menu>