Actionbar Sherlock:设置和隐藏标题栏

gcl*_*cl1 10 android actionbarsherlock android-actionbar

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

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

final ActionBar actionBar = (ActionBar) findViewById(R.id.actionBar);
actionBar.setTitle("test title");
Run Code Online (Sandbox Code Playgroud)

相应的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" />
Run Code Online (Sandbox Code Playgroud)

(这是以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);
Run Code Online (Sandbox Code Playgroud)

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

"The method setDisplayShowTitleEnabled(boolean) is undefined for the type
 ActionBar."
Run Code Online (Sandbox Code Playgroud)

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

非常感谢.

Mat*_*ers 40

设置ActionBar标题

setTitle("Title")
Run Code Online (Sandbox Code Playgroud)

隐藏和显示 ActionBar

getSupportActionBar().hide();
getSupportActionBar().show();
Run Code Online (Sandbox Code Playgroud)


ben*_*lis 2

您似乎混合了两种不同的 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