【Android開発】ImageViewをDataBindingする方法【Kotlin】

ImageVIewにDataBindingする方法です。

まずはレイアウトファイル
hoge.xml

1
2
<ImageView
android:id="@+id/icon_menu"/>

次にFragment or Activityファイル
hoge.kt

1
binding.iconMenu.setImageResource(R.drawable.ic_action_hoge)

以上。

めちゃくちゃハマったけど最終的にシンプルに書けば良いだけだった。。
ググると複雑なやり方が出てくるのはどういうアレなんだろう。
これが正式なやり方じゃないかもだけど、とりあえず動いたので良かった。

【Android開発】ImageViewをDataBindingする方法【Kotlin】

https://reon777.com/2022/03/09/android-data-binding-for-imageView/

Author

reon777

Posted on

2022-03-09

Updated on

2026-06-30

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×