public abstract class BaseActivity extends AppCompatActivity {
private Boolean isShowBackimge;
private Boolean isShowMoreimg;
private String title;
private int baseLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
baseLayout = createBaseLayout();
if(baseLayout !=0){
setContentView(createBaseLayout());
ButterKnife.bind(this);
}
initView();
}
protected abstract int createBaseLayout();
protected abstract void initView();
protected void setNavBar(boolean isShowBackimge,boolean isShowMoreimg,String title){
View childAt = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
if(childAt!=null&&baseLayout!=0){
ImageView backimge = (ImageView) childAt.findViewById(R.id.backimge);
ImageView moreimge = (ImageView)childAt. findViewById(R.id.moreimge);
TextView title1 = (TextView) childAt.findViewById(R.id.title);
backimge.setVisibility(isShowBackimge?View.VISIBLE:View.INVISIBLE);
moreimge.setVisibility(isShowMoreimg?View.VISIBLE:View.INVISIBLE);
title1.setText(!TextUtils.isEmpty(String.valueOf(title))?String.valueOf(title):"");
}
};
}
在这里插入代码片
BaseActivity里面设置了Toolbar或者NavgeActionBar
最新推荐文章于 2020-03-03 09:46:47 发布