我是ActionBarSherlock的新手,我有两个问题:
首先,我只想设置操作栏的 Headers ,但是当我这样称它时它不起作用:
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionBar);
actionBar.setTitle("test title");
相应的xml对象如下所示:
<com.myapp.prototype.ActionBar
android:id="@+id/actionBar2"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
(这是在github示例之后建模的:https://github.com/johannilsson/android-actionbar/blob/master/actionbarexample/src/com/markupartist/android/actionbar/example/HomeActivity.java) . 在网络上的其他地方,我看到了对getSupportActionBar()的引用,但我不清楚如何或在何处调用它 .
其次,在另一个地方,我只想完全隐藏Activity的 Headers 栏 . 我试图通过调用:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
但我甚至无法编译 . 我得到的错误是:
"The method setDisplayShowTitleEnabled(boolean) is undefined for the type
ActionBar."
在这两种情况下,我猜Actionbar Sherlock覆盖都涉及到这个问题 . 有任何建议如何使这项工作?
非常感谢 .
3 回答
您似乎混合了两个不同的ActionBar实现 . ActionBarSherlock是Google提供的兼容性库的扩展 . 与ActionBarSherlock一起使用的方法几乎与Android 3.0中的本机ActionBar相同http://actionbarsherlock.com/
提供的Github链接(以及您正在使用的代码)是操作栏https://github.com/johannilsson/android-actionbar的自定义实现 .
我建议你使用ActionBar sherlock并按照这里的使用指南http://actionbarsherlock.com/usage.html
这里还有一个ActionBarSherlock入门视频http://www.youtube.com/watch?feature=player_embedded&v=4GJ6yY1lNNY
设置ActionBar Headers
隐藏并显示ActionBar
您需要导入com.actionbarsherlock.view.Window,以便它秘密使用此方法的长版本 .