ActionBarSherlock - 标签出现以上动作条与自定义视图 [英] ActionBarSherlock - Tabs appearing ABOVE actionbar with custom view
问题描述
我想创建没有应用程序的标志/文字的动作条,并配有中央的画面,我知道这是可能的自定义视图,这里是我的code:
I Am trying to create an actionbar without the app logo/text, and with a centralised picture, and i know it is possible with a custom view, here is my code:
protected void initActionBar()
{
RelativeLayout custom = new RelativeLayout(getApplicationContext());
ActionBar.LayoutParams params = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
custom.setLayoutParams(params);
custom.setGravity(Gravity.CENTER);
custom.setBackgroundDrawable(getResources().getDrawable(R.drawable.background_grad_grey_rounded));
ImageView image =new ImageView(getApplicationContext());
image.setBackgroundResource(R.drawable.ic_launcher);
custom.addView(image);
ab = getSupportActionBar();
ab.setDisplayShowCustomEnabled(true);
ab.setCustomView(custom);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
tab_connect = ab.newTab();
tab_connect.setText("CONNECT");
tab_connect.setTabListener(this);
tab_discover = ab.newTab();
tab_discover.setText("DISCOVER");
tab_discover.setTabListener(this);
tab_simplify= ab.newTab();
tab_simplify.setText("SIMPLIFY");
tab_simplify.setTabListener(this);
ab.addTab(tab_simplify);
ab.addTab(tab_discover);
ab.addTab(tab_connect);
ab.setDisplayShowTitleEnabled(false);
ab.setDisplayShowHomeEnabled(false);
}
然而,当我隐藏的标志,我下面的选项卡中的动作条的变化,像这样:
however when i hide the logo, the actionbar shifts below my tabs like so:
但如果我设置ab.setDisplayShowHomeEnabled(真)的动作条出现在它的正确位置(但我不想徽标):
but if i set ab.setDisplayShowHomeEnabled(true) the actionbar appears in it's right place (but with the logo which i don't want):
我究竟做错了什么?
推荐答案
下面是一个简单的解决方法:
Here's a simple workaround :
使用您的onCreate方法如下:
use the following in your onCreate method :
View homeIcon = findViewById(android.R.id.home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
这完全崩溃home键。
this collapses the home button completely.
PS:我使用的标准动作条但这应该工作一样
PS : i'm using standard ActionBar but this should work the same
或
如果你想在夏洛特动作条为支持比你要使用此
if you want to support in Sherlock Actionbar to than you have to use this
actionBar.setLogo(null); // forgot why this one but it helped
View homeIcon = findViewById(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.id.home : R.id.abs__home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
((View) homeIcon).setVisibility(View.GONE);
actionBar.setDisplayShowTitleEnabled(false);
这篇关于ActionBarSherlock - 标签出现以上动作条与自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!