[英]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.