【问题标题】:How can I set attr value in ImageView from class?如何在类的 ImageView 中设置 attr 值?
【发布时间】:2017-10-13 13:33:51
【问题描述】:
<ImageView
android:id="@+id/avatar_repo_list"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="?attr/avatar_repo_icon"
tools:ignore="ContentDescription" />
像这样,但来自班级
【问题讨论】:
标签:
android
xml
imageview
attr
【解决方案2】:
在你activity中,使用findViewById()获取这个image view的引用,然后你就可以使用这个引用来调用方法了。然后这些方法设置image view 的属性值。这是示例性的 sn-p。
ImageView img=(ImageView) findViewById(R.id.avatar_repo_list);
//Suppose I need to set the Drawable programatically
img.setImageDrawable(R.drawable.my_image);