티스토리 뷰
반응형
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 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- retrofit
- flutter_new_badger
- Kotlin
- error
- Flutter
- java
- 알고리즘
- message
- node.js
- app bundle
- API
- listener
- 재귀함수
- bitmap
- Custom
- Firebase
- ec2
- direction
- FCM
- ExoPlayer
- Token
- https
- ios
- GitHub
- Hilt
- android
- Crop
- 코딩테스트
- Android Studio
- ScrollView
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함