Makes it easier to work with Android View Binding.
android {
...
buildFeatures {
viewBinding true
}
}
dependencies {
...
implementation 'com.danl.viewbindinghelper:viewbindinghelper:1.0.2'
}
-keep class com.example.app.databinding.* {
<methods>;
}
class MainActivity : ViewBindingActivity<ActivityMainBinding>() {
override fun onBindingCreated(savedInstanceState: Bundle?) {
binding.textView.text = "Hello World!"
}
}
class SampleFragment : ViewBindingFragment<FragmentSampleBinding>() {
override fun onBindingCreated(savedInstanceState: Bundle?) {
binding.textView.text = "Hello World!"
}
}
class SampleDialogFragment : ViewBindingDialogFragment<DialogSampleBinding>() {
override fun onBindingCreated(savedInstanceState: Bundle?) {
binding.textView.text = "Hello World!"
}
}
val dialog = Dialog(requireContext())
dialog.bind<DialogSampleBinding> {
textView.text = getString(R.string.bind_dialog)
}
dialog.show()
dialog.binding<DialogSampleBinding>().let {
Toast.makeText(
requireContext(),
it.textView.text,
Toast.LENGTH_LONG
).show()
}
AlertDialog.Builder(requireContext()).bind<DialogSampleBinding> {
textView.text = getString(R.string.bind_dialog)
}.show()
val view = View.inflate(requireContext(), R.layout.dialog_sample, null)
view.binding<DialogSampleBinding>().run {
textView.text = getString(R.string.bind_view)
}