【问题标题】:implementing the action bar in the android在android中实现动作栏
【发布时间】:2012-06-20 13:02:28
【问题描述】:

我想为我自己的 android 应用程序实现一个操作栏,就像图片底部的那个一样。 搜索了很多,但是出现了很多错误。

我尝试了一些库来寻求帮助,例如:Greendroid 和 ActionBarSherlock,但它们都不起作用,或者我无法完美地使用它们! ..

我真的需要在我的应用程序中使用该操作栏。

如果有人可以帮助我提供一些示例或代码或向我解释,我将不胜感激。

非常感谢:) ..

【问题讨论】:

  • "但是出现了很多错误。"使用 uiOptions="splitActionBarWhenNarrow" 是否有任何错误?
  • NO 不在该行,另一个用于 style.xml 文件中的“WindowsTitleBackground”! .. 我读到了 splitactionbarwhenNarrow 但我无法应用它,因为错误:(
  • 它说 WindowsTitleBackground 不是 android 的资源 .. 那是我使用 GreenDroid Library 的时候! ..

标签: android eclipse implementation android-actionbar


【解决方案1】:

您可以使用 SplitActionBar。您的应用程序应该在 Android 4.0(API 级别 14)或更高版本上运行

解决方法是在顶部栏中始终有一个项目,以防止底部内容永远适合那里,从而强制所有内容进入底部栏。看看另一个用户的这个示例项目:

<?xml version="1.0" encoding="utf-8"?
<manifest package="com.commonsware.android.actionbarbc"
          xmlns:android="http://schemas.android.com/apk/res/android">

  <application android:hardwareAccelerated="true"
               android:icon="@drawable/cw"
               android:label="@string/app_name">
    <activity android:label="@string/app_name"
              android:name=".InflationDemo"
              android:uiOptions="splitActionBarWhenNarrow">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="4"
            android:targetSdkVersion="11" />
  <supports-screens android:anyDensity="true"
                    android:largeScreens="true"
                    android:normalScreens="true"
                    android:smallScreens="true"
                    android:xlargeScreens="true" />
</manifest>

他在他的活动中使用了这个代码:

private void setupActionBar() {
ActionBar actionBar = getActionBar();

ViewGroup v = (ViewGroup)LayoutInflater.from(this)
    .inflate(R.layout.conversation_list_actionbar, null);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
        ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(v,
        new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_VERTICAL | Gravity.RIGHT));

mUnreadConvCount = (TextView)v.findViewById(R.id.unread_conv_count);
}

http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

【讨论】:

  • java.lang.RuntimeException:无法实例化活动 ComponentInfo{me.adly.action/me.adly.action.InflationDemo}:java.lang.ClassNotFoundException:me.adly.action.InflationDemo 它给出我在日志猫跟踪器中的那个错误!?那么有什么问题呢?
  • 在您的项目中找不到 InflationDemo 活动。检查您的清单和活动名称或您的意图对象。
  • 成功了 :),这就是我看到的! :postimage.org/image/tsyneui1j可以给我上面sn-p的源码链接吗?
  • 这是我从另一个用户那里找到的 sn-p 链接:stackoverflow.com/questions/8465258/… 如果我的回答有帮助,请接受,谢谢。
【解决方案2】:

我认为您需要查看一个名为 SplitActionBar 的东西。

这方面的文档是here。

通过简要阅读,它仅适用于“窄”屏幕,并且您通过在 AndroidManifest.xml 文件的 or 元素中添加 uiOptions="splitActionBarWhenNarrow" 来声明要使用拆分操作栏。

你也许可以强制它一直出现,但我不知道,因为我以前没用过。

我希望这会有所帮助。

【讨论】:

  • 我起初读到过,但是我找不到任何可以完美应用的示例代码,你能帮我吗?
  • 我成功了,但是你说的有一个问题,当我在菜单中添加5个元素时,操作栏只显示3个元素并且不像上图那样?那么你认为问题是什么?我把你所说的:splitactionbarwhennarow,但仍然无法正常工作..???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
相关资源
最近更新 更多