當項目需要統(tǒng)一標題欄的時候,官方的答案是每個布局里面include一個布局,想來是多么麻煩,那哪能叫程序員的做法。
自己封裝的baseactivity的關鍵代碼
private void initActionBar() {
actionBar = getSupportActionBar();
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
View view = LayoutInflater.from(this).inflate(R.layout.aty_news_bar, null);
actionBar.setCustomView(view, params);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(false);
actionBar.setElevation(0);
Toolbar parent = (Toolbar) view.getParent();
parent.setContentInsetsAbsolute(0, 0);
}
放在baseactivity里面,不用setcontentview