public class MainActivity extends BaseActivity{
@Override
protected void setRootView() {
super.setRootView();
setContentView(R.layout.activity_main);
}
@Override
protected void initWidght() {
super.initWidght();
setTitleName(getResources().getString(R.string.chat));//title
// setTitleBack(false,R.mipmap.ic_search);//有图标,但不是返回
//setTitleBack(true,0);//返回
// setTitleRightText("保存");//右侧文字
showTitleRes(R.id.title_add,R.id.title.setting);//扩展menu(图标)
//goneTitleRes(R.id.title_add);隐藏图标,一般用不到
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.title_back){
workFragment.titleSearch();
}
}
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.title_add://添加
break;
case R.id.title_apps://应用break;
case R.id.title_setting://设置
break;
}
return super.onMenuItemClick(item);
}
}
Toolbar其他设置
1.去掉左边空白,在style文件里设置
<style parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item>@color/colorAppTheme</item>
<item>@color/colorAppTheme</item>
<item>@color/colorAccent</item>
<item tools:ignore="NewApi">@style/MyToolBar</item>
</style>
<style parent="Widget.AppCompat.Toolbar">
<!--左边边距-->
<item>0dp</item>
</style>