Android開發(32) Actionbar 常用方法
- 2020 年 3 月 16 日
- 筆記
設置標題:
actionBar.setTitle("關於我們");
顯示「返回箭頭的按鈕"
actionBar.setDisplayHomeAsUpEnabled(true);
監聽返回按鈕的 事件
public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { finish(); return true; } return super.onOptionsItemSelected(item); }
隱藏圖標logo
我採用了一種使用將logo設置透明的方式:
getActionBar().setIcon( new ColorDrawable(getResources().getColor(android.R.color.transparent)));
參考:
http://stackoverflow.com/questions/14606294/remove-icon-logo-from-action-bar-on-android