![](/img/trans.png)
[英]How can i remove icon and title from ActionBar in Android on startup?
[英]How can I remove title and icon completetly in Actionbar sherlock?
我使用动作栏Sherlock,但需要从栏中删除标题和图标。
我用了
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
它起作用了,图标和标题消失了,但我的物品出现在右边。 有什么办法可以完全删除标题和图标,而不是隐藏它们。 我在堆栈溢出中发现了类似的问题,但没有人回答。
编辑
Before my bar look like: -- Icon Title MenuItem1 MenuItem2--
After my bar look like: -- MenuItem1 MenuItem2--
I want my bar look like: -- MenuItem1 MenuItem2
您的“菜单项”将永远不会向左对齐。 它们将向右对齐。 左侧是标题和图标(当前已删除)和导航(标签,列表等)的位置。 如果您有足够的操作栏项目,它们将流到左侧,但始终会从右侧开始。 无法通过Android SDK更改此设置。
您可以参考此代码,然后获得解决方案...只需根据您的要求进行申请...。
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
RelativeLayout relative = new RelativeLayout(getApplicationContext());
TextView tv1 = new TextView(this);
tv1.setText("Test1");
tv1.setTextColor(Color.GREEN);
tv1.setPadding(3,13,3, 12);
tv1.setId(1);
tv1.setOnClickListener(this);
TextView tv2 = new TextView(this);
tv2.setText("Test2");
tv2.setTextColor(Color.GREEN);
tv2.setPadding(3,13,3,12);
tv2.setId(2);
tv2.setOnClickListener(this);
TextView tv3 = new TextView(this);
tv3.setText("Test3");
tv3.setTextColor(Color.GREEN);
tv3.setPadding(3,13,3, 12);
tv3.setId(3);
tv3.setOnClickListener(this);
TextView tv4 = new TextView(this);
tv4.setText("Test3");
tv4.setTextColor(Color.GREEN);
tv4.setPadding(3,13,3, 12);
tv4.setId(4);
tv4.setOnClickListener(this);
LinearLayout ll = new LinearLayout(this);
ll.addView(tv1);
ll.addView(tv2);
ll.addView(tv3);
ll.addView(tv4);
relative.addView(ll);
actionBar.setCustomView(relative);
getSupportActionBar().setIcon(android.R.color.transparent);
您可以使用操作栏上的上下文菜单来执行此操作。 查看Sherlock ABS演示,其中有一个活动:ActionModes,它显示了一个非常简单的示例,可能对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.