Search code examples
androidxmlimageviewattr

How can I set attr value in ImageView from class?


<ImageView
    android:id="@+id/avatar_repo_list"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="?attr/avatar_repo_icon"
    tools:ignore="ContentDescription" />

like this, but from the class


Solution

  • First of all get the reference of your image-view in your Activity class through "ID", and then add attr value like this:

    Android: how to get value of an attribute in code?