반응형
TextView 를 사용할 때 아래와 같이 TextView 와 함께 Drawable 을 사용할 때가 있다.
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/size20"
android:layout_marginTop="@dimen/size08"
android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/size04"
android:gravity="center"
android:text="string"
android:textColor="@color/white"
app:drawableLeftCompat="@drawable/svg_icon"
app:drawableTint="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
<TextView
이 때 사용한 Drawable 을 동적으로 바꿔줘야 할 때 아래와 같이 사용할 수 있다.
tv.apply {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.svg_icon_2, //left
0, // top
0, //right
0 //bottom
)
}
추가 팁 ! 색상을 바꿔줘야 할 때
tv.compoundDrawables[0].setTint(getColor(R.color.red))
반응형
'안드로이드' 카테고리의 다른 글
[Android Studio] TextWatcher Utils 로 사용하기 (코틀린) (1) | 2023.11.03 |
---|---|
[Android Studio] TextInputLayout Custom 사용하기 ! (0) | 2023.11.03 |
[Android Studio] Padding 값 동적으로 변경하기 (코틀린) (0) | 2023.09.21 |
[Android Studio] List< Object > 조건에 따라 리스트 중복제거 (코틀린) (0) | 2023.09.15 |
[Android Studio] flexbox Layout 사용하기 (코틀린) (0) | 2023.09.14 |