我正在我的渐变中添加
buildFeatures {
viewBinding true
}
public class MainActivity3 extends AppCompatActivity {
ActivityMain3Binding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMain3Binding.inflate(getLayoutInflater());
binding=DataBindingUtil // don't found
View view = binding.getRoot();
setContentView(view);
binding.EdName.setText("test text");
}
我需要帮助或好的和新的教程来理解数据绑定
您还需要在应用程序级别build.gradle
:中启用数据绑定
android {
...
buildFeatures {
dataBinding true
viewBinding true
}
}
1-在应用程序的build.gradle中,像往常一样设置数据绑定
2-添加编译器依赖
3-然后在文件顶部应用插件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
buildFeatures {
dataBinding true
}
}
dependencies {
kapt "com.android.databinding:compiler:3.0.1"
}
您还需要在build.gradle 中启用数据绑定
buildFeatures{dataBinding trueviewBinding true}