【问题标题】:Migration from SherlockActionBar to ActionBar [duplicate]从 SherlockActionBar 迁移到 ActionBar [重复]
【发布时间】:2014-06-21 07:00:48
【问题描述】:

我刚刚迁移到原生 actionBar,之前使用 ABS 效果很好。 现在,我在为 API 16+ 开发时不再需要兼容性

我更改了所有引用,现在,我的菜单仅以文本显示,带有物理按钮,它不会显示在操作栏中...

我不知道我错过了什么......

这是我的代码:

main.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/menu_sync"
    android:icon="@drawable/ic_action_update"
    android:orderInCategory="80"
    android:showAsAction="ifRoom"
    android:title="Sync"/>
<item
    android:id="@+id/more"
    android:icon="@drawable/ic_action_core_overflow"
    android:orderInCategory="90"
    android:showAsAction="always"
    android:title="See more options">
    <menu>
        <item
            android:id="@+id/menu_send_coords"
            android:icon="@drawable/ic_action_send_coords"
            android:orderInCategory="80"
            android:showAsAction="ifRoom"
            android:title="Send Coords"
            android:visible="true"/>
        <item
            android:id="@+id/menu_foto"
            android:icon="@drawable/ic_action_device_access_camera"
            android:orderInCategory="100"
            android:showAsAction="ifRoom"
            android:title="Foto"
            android:visible="true"/>
    </menu>
</item>

在我的活动中:

public class DashBoard extends BaseActivity { //BaseActivity extends ActionBarActivity
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

我尝试将菜单 xml 更改为另一个(谷歌示例),但它不起作用。

我搜索了所有对 Sherlock* 的引用并将它们全部替换

在我的清单中我有:

  <application
    ...
    android:theme="@style/Theme.AppCompat" >

在我的 style.xml 我有:

     <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <!-- nothing API level dependent yet -->
</style>

    <!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

我已遵循以下每个步骤: http://www.grokkingandroid.com/migrating-actionbarsherlock-actionbarcompat/

What are the common issues when migrating from ActionBarSherlock to ActionBarCompat?

ActionBarCompat menu item is not showing

我不知道我还能做什么??? 任何帮助将不胜感激!

【问题讨论】:

  • 所以您阅读了ActionBarCompat menu item is not showing 的问题,但没有按照它所说的去做?
  • 你是对的!它现在正在工作。我认为它只是为了兼容性......阅读太快了!发送!!!

标签: android android-actionbar actionbarsherlock android-actionbar-compat


【解决方案1】:

我认为您应该更改您的 style.xml 和您的 Android 主题,因为您不再需要 Android appcompat 库。

styles.xml:

<style name="AppBaseTheme" parent="@style/Theme.Holo.Light.DarkActionBar">
<!-- nothing API level dependent yet -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

AndroidManifest.xml:

    <application
        android:theme="@style/AppTheme"
    ...

【讨论】:

  • 试过了还是不行
猜你喜欢
  • 2015-04-04
  • 2014-08-22
  • 2011-01-07
  • 2012-06-22
  • 2016-10-31
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
  • 2022-10-11
相关资源
最近更新 更多