简体   繁体   English

操作栏未随AppCompat显示

[英]Actionbar not shown with AppCompat

I am backporting my app to API7 with AppCompat and have a problem with the actionbar. 我正在使用AppCompat将我的应用程序移植到API7,并且操作栏出现问题。

When I use FragmentActivity the actionbar is shown on my phone (API18), but with ActionBarActivity it shows up as the optionmenu by pressing the menubutton. 当我使用FragmentActivity ,操作栏显示在我的手机上(API18),但是使用ActionBarActivity它会通过按下menubutton显示为optionmenu。

On the emulator with API7 the actionbar is always shown as an optionsmenu. 在具有API7的模拟器上,操作栏始终显示为选项菜单。

Any ideas? 有任何想法吗?

Use the compat name space for your menu items like this: 使用compat名称空间为您的菜单项,如下所示:

<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>

Related to a duplicate that points to this post , I was having trouble making my buttons appear as action items instead of overflow items, despite having showAsAction set to always . 指向此帖子的副本相关,我无法将我的按钮显示为操作项而不是溢出项,尽管showAsAction always设置为。 I managed to coerce it by extending my activity with Activity instead of ActionBarActivity . 我设法通过使用Activity而不是ActionBarActivity扩展我的活动来强制它。 According to this answer , this is acceptable if you don't need to support api levels below 11. 根据这个答案 ,如果您不需要支持低于11的api级别,这是可以接受的。

...extends ActionBarActivity : ...extends ActionBarActivity

扩展ActionBarActivity

...extends Activity : ...extends Activity

在此输入图像描述

I do debug with Doogee Valencia Y100Pro, and menu as "three little square" not visible, but when I extended my MainActivity with android.support.v7.app.ActionBarActivity , then I obtain text/icon menu in action bar. 我用Doogee Valencia Y100Pro进行调试,菜单为“三个小方块”不可见,但是当我使用android.support.v7.app.ActionBarActivity扩展我的MainActivity时,我在操作栏中获取了文本/图标菜单。 Next screenshot and menu.xml 下一个截图和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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM