Android|Android 自定义baseActivity

布局文件


BaseActivity.class
public abstract class BaseActivity extends AppCompatActivity { private TextView tv_base_back, tvBaseTitle, tvBaseRight; private LinearLayout llBaseContainer; public Handler handler = new Handler(Looper.getMainLooper()); public Activity activity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); initViews(); View.inflate(this, setContainer(), llBaseContainer); //设置内容 ButterKnife.bind(this); activity = this; } /** * 初始化 */ private void initViews() { llBaseContainer = findViewById(R.id.llBaseContainer); tv_base_back = findViewById(R.id.tv_base_back); tvBaseTitle = findViewById(R.id.tvBaseTitle); tvBaseRight = findViewById(R.id.tvBaseRight); tv_base_back.setOnClickListener(v -> finish()); } /** * 布局文件 */ public abstract int setContainer(); /** * 无标题 */ public void setNoTitle() { findViewById(R.id.rlBaseActivityTitle).setVisibility(View.GONE); } /** * 右侧按钮 */ public void setRight(String text, View.OnClickListener onClickListener) { tvBaseRight.setVisibility(View.VISIBLE); tvBaseRight.setText(text); tvBaseRight.setOnClickListener(onClickListener); } /** * 无返回键 */ public void setNoBackBtn() { tv_base_back.setVisibility(View.GONE); } /** * 设置标题 * * @param title */ public void setTvTitle(String title) { tvBaseTitle.setText(title); } /** * 显示toast提示 */ public void showToast(String text) { handler.post(() -> { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); }); }
相关引用
ndk {
//设置支持的SO库架构
abiFilters 'armeabi', 'armeabi-v7a'
// , 'x86_64', 'arm64-v8a'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
implementation 'com.alibaba:fastjson:1.2.31'
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:26.1.0'
allprojects{
repositories{
maven {
url "https://jitpack.io"
}
}
}
使用方法:
Android|Android 自定义baseActivity
文章图片
效果图 对了还有一些乱七八糟的权限
【Android|Android 自定义baseActivity】






    推荐阅读