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:
but if i set ab.setDisplayShowHomeEnabled(true) the actionbar appears in it's right place (but with the logo which i don't want):
What am i doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…