Actionbar Sherlock:设置和隐藏标题栏

时间:2012-05-29 22:23:16

标签: android actionbarsherlock android-actionbar

我是ActionBarSherlock的新手,我遇到两个问题:

首先,我只想设置操作栏的标题,但是当我这样称呼它时它不起作用:

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的标题栏。我试着通过调用:

来做到这一点
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);

但我甚至无法编译。我得到的错误是:

"The method setDisplayShowTitleEnabled(boolean) is undefined for the type
 ActionBar."

在这两种情况下,我猜Actionbar Sherlock覆盖都涉及到这个问题。有任何建议如何使这项工作?

非常感谢。

3 个答案:

答案 0 :(得分:40)

设置ActionBar标题

setTitle("Title")

隐藏并显示ActionBar

getSupportActionBar().hide();
getSupportActionBar().show();

答案 1 :(得分:2)

您似乎正在混合两个不同的ActionBar实现。 ActionBarSherlock是Google提供的兼容性库的扩展。与ActionBarSherlock一起使用的方法几乎与Android 3.0 + http://actionbarsherlock.com/中的本机ActionBar相同

提供的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

答案 2 :(得分:0)

您需要导入com.actionbarsherlock.view.Window,以便秘密使用此方法的长版本。

相关问题