@明月照天涯丶 解决了,baseActivity 写一个protected abstract T getViewBinding(),子activity实现xxxBinding.inflate(getLayoutInflater()),再写一个protected abstract void setTitleBar(),在子activity里对titleView操作
在base里面的onCreate方法里
mViewBinding = getViewBinding();
rootLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.activity_base, null, false);
View childView = mViewBinding.getRoot();
childView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
rootLayout.addView(childView);
setContentView(rootLayout);
//然后find一下titleview的资源大致就是这样
databinding动态添加viewdatabinding可以通过DataBindingUtil.setContentView加载布局,和activity的 setContentView类似,如果要用Fragm...