反射初始化ViewBinding和ViewModel

This commit is contained in:
Dboy
2020-09-26 15:53:27 +08:00
parent b247b44f50
commit f14f5e9b32
9 changed files with 61 additions and 80 deletions

View File

@ -65,6 +65,9 @@ android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
buildFeatures {
viewBinding = true
}
}
dependencies {

View File

@ -22,7 +22,7 @@
android:theme="@style/base_AppTheme"
tools:ignore="UnusedAttribute">
<activity
android:name="com.quyunshuo.base.mvvm.v.MyActivity"
android:name=".MyActivity"
android:screenOrientation="portrait"
android:theme="@style/base_AppTheme">
<intent-filter>

View File

@ -0,0 +1,27 @@
package com.quyunshuo.androidbaseframemvvm;
import com.quyunshuo.androidbaseframemvvm.databinding.MyActivityLayoutBinding;
import com.quyunshuo.base.mvvm.v.BaseFrameActivity;
import org.jetbrains.annotations.NotNull;
/**
* @author DBoy
* @date 2020/9/26
* Class 描述 :
*/
public class MyActivity extends BaseFrameActivity<MyActivityLayoutBinding, MyViewModel> {
@Override
protected void initView() {
getMViewModel().test();
getMBinding().testTv.setText("反射初始化 ViewBinding");
}
@Override
protected void initViewObserve() {
}
}

View File

@ -0,0 +1,17 @@
package com.quyunshuo.androidbaseframemvvm;
import android.util.Log;
import androidx.lifecycle.ViewModel;
/**
* @author DBoy
* @date 2020/9/26
* Class 描述 :
*/
public class MyViewModel extends ViewModel {
public void test(){
Log.e("DJC", "AAA");
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<TextView
android:id="@+id/test_Tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#000"
android:textSize="20sp" />
</androidx.constraintlayout.widget.ConstraintLayout>