简体   繁体   English

如何向ActionBarSherlock添加标题

[英]How to add title to ActionBarSherlock

i can't set title to Action bar sherlock. 我无法设置Action bar sherlock的标题。 Here is my code: 这是我的代码:

public void addNavaigationBar(){

       //Create Action Bar sherlock
ActionBar navigation_bar =  getSupportActionBar();



//Setting standart navigation bar view
navigation_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);



navigation_bar.setDisplayHomeAsUpEnabled(true);
navigation_bar.setDisplayShowTitleEnabled(true);
navigation_bar.setTitle("Testing");



}

I want to add Testing tile but it don't changes. 我想添加测试图块但不会更改。 This should be easy but i can't find it. 这应该很容易,但我找不到它。

Also i am wondering if i could create this navigation bar on top and Tab bar on bottom with Action bar sherlock ? 此外,我想知道我是否可以在顶部创建此导航栏和底部的Tab栏与操作栏sherlock?

Thanks. 谢谢。

EDIT: Sorry this is working, it's my other mistake. 编辑:对不起,这是有效的,这是我的另一个错误。

Add this into your onCreate 将其添加到您的onCreate

getSupportActionBar().setTitle("<Your Title Here>")

example: 例:

public class MainActivity extends SherlockActivity {
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

          //Actionbar Stuff
          getSupportActionBar().setTitle("Hope This Helped!")

    }
//REST OF CLASS HERE
}

First off, I can't find the documentation, but it's not considered best practices to place Android tabs on the bottom - something about that being how it's done on iOS. 首先,我找不到文档,但是将Android标签放在底部并不是最佳实践 - 这就是在iOS上完成的方式。 Theoretically, though, it could be possible with SplitWhenNarrow if you filled the top bar with enough other things - but it would be unreliable, because on a tablet, for example, there might be enough space to load the tabs with everything else on the top bar. 从理论上讲,如果你在顶部栏中填充了足够的其他东西,那么它可以用SplitWhenNarrow实现 - 但它是不可靠的,因为在平板电脑上,例如,可能有足够的空间来加载标签,顶部的其他东西都在顶部酒吧。

Edit~ Just tested in my code - you can leave out the show title method(true) and still call setTitle on the actionbar, and it sets the title properly. 编辑〜刚刚在我的代码中测试 - 您可以省略show title方法(true)并仍然在操作栏上调用setTitle,并正确设置标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM