ColorFilter를 TextView의 CompoundDrawable에 걸어주세요.
개요
안드로이드의 TextView에서 설정할 수 있는CompoundDrawable에 ColorFilter를 설치하는 방법에 대해 설명했습니다.
CompoundDrawable
TextView는 텍스트와 인접한 이미지, 즉 CommundDrawable을 설정할 수 있습니다.<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_drawable_white"
/>
이것을 사용하면 ImageView와 TextView를 조합할 필요가 없기 때문에 간단하게 레이아웃 구성을 할 수 있습니다.표시되는 위치는 문자의 위아래 좌우입니다.위의 예는 drawable Left이기 때문에 텍스트의 왼쪽에 Drawable이 표시됩니다.
ColorFilter 중단 동기
내가 만든 프로그램에서 사용자는 프로그램 내 View 색상을 자유롭게 설정할 수 있습니다
ImageView를 사용하는 곳에는 흰색 Drawable이 준비되어 있으며 ColorFilter 방법을 사용하여 사용자의 색상 설정을 반영합니다.
하지만 ColorFilter를 어떻게 치는지 몰라서 Drawable의 색깔은 항상 흰색입니다.
이루어지다
설치 방법
조사해 보니 곧 방법을 찾았다.
Setting the Color of a TextView Drawable for Android
이루어지다
보도의 인코딩이 그렇게 예술적이지 않기 때문에 다른 작법을 시도해 보자.Kotlin이면 짧게 쓸 수 있어요.textView.compoundDrawables?.forEach {
it?.colorFilter = PorterDuffColorFilter(fontColor, PorterDuff.Mode.SRC_IN)
}
설치 후
보시다시피 ColorFilter는CompoundDrawable에 걸려 있습니다.
보태다
ViewStub 내 TextView에 좋지 않기 때문에 사용하는 것이 좋습니다TextViewCompat.setCompoundDrawableTintList
.textView?.also {
it.setTextColor(fontColor)
TextViewCompat.setCompoundDrawableTintList(it, ColorStateList.valueOf(fontColor))
}
총결산
Commund Drawarble에 ColorFilter를 걸려면 TextView의compound Drawables에서 각각의 Drawable 대상을 실행할 수 있습니다.TextView를 상속받은 버튼 등도 동일하게 적용된다.
Reference
이 문제에 관하여(ColorFilter를 TextView의 CompoundDrawable에 걸어주세요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/toastkidjp/items/5f5ff10fc3eeb67f115d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_drawable_white"
/>
설치 방법
조사해 보니 곧 방법을 찾았다.
Setting the Color of a TextView Drawable for Android
이루어지다
보도의 인코딩이 그렇게 예술적이지 않기 때문에 다른 작법을 시도해 보자.Kotlin이면 짧게 쓸 수 있어요.
textView.compoundDrawables?.forEach {
it?.colorFilter = PorterDuffColorFilter(fontColor, PorterDuff.Mode.SRC_IN)
}
설치 후
보시다시피 ColorFilter는CompoundDrawable에 걸려 있습니다.
보태다
ViewStub 내 TextView에 좋지 않기 때문에 사용하는 것이 좋습니다
TextViewCompat.setCompoundDrawableTintList
.textView?.also {
it.setTextColor(fontColor)
TextViewCompat.setCompoundDrawableTintList(it, ColorStateList.valueOf(fontColor))
}
총결산
Commund Drawarble에 ColorFilter를 걸려면 TextView의compound Drawables에서 각각의 Drawable 대상을 실행할 수 있습니다.TextView를 상속받은 버튼 등도 동일하게 적용된다.
Reference
이 문제에 관하여(ColorFilter를 TextView의 CompoundDrawable에 걸어주세요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/toastkidjp/items/5f5ff10fc3eeb67f115d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(ColorFilter를 TextView의 CompoundDrawable에 걸어주세요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/toastkidjp/items/5f5ff10fc3eeb67f115d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)