Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- prolificinteractive/material-calendarview
- podinit
- RestAPI
- addTextChangedListner
- DialogFragment
- cocoapod
- PostgreSQL
- livedata
- springboot
- android
- viewmodel
- backgroundTint
- 리눅스
- Button
- editText
- calendar
- Dialog
Archives
- Today
- Total
코코딩딩
[안드로이드/android] color 사용하기 (java,xml) 본문
안드로이드에서 text의 색상을 setTextColor를 이용해 변경하려고 했지만 색상을 선택하는 방법을 잘 몰라 찾아본 내용을 정리했다.
xml 에서 color 사용하기
<TextView
android:id="@+id/pw_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="숫자,영문, 특수문자 조합으로 8자~20자"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>
위의 코드처럼 @color/colorPrimary 라고 하면 values 폴더에 있는 colors.xml 에 등록되어 있는 색을 불러올 수 있다.
java코드에서 사용하기
위에서 했던 것 처럼 자바 코드에서 특정 이벤트가 일어날 때 텍스트의 색상을 변경하고자 할 때는 다음과 같이 한다.
binding.pwError.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
colors.xml
자신이원하는 색상의 이름과 16진수 색상코드를 xml에 작성해 두면 위와 같은 방법으로 색상을 사용할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3a6060</color>
<color name="red">#da1e28</color>
<color name="black">#161616</color>
</resources>
'일단기록 > 매일기록' 카테고리의 다른 글
[스프링/springboot] restapi 만들기 (mybatis, postgresql) (0) | 2022.05.13 |
---|---|
[안드로이드/android] Timer 제한시간 만들기 (0) | 2022.05.12 |
[안드로이드/android] 차트 라이브러리 (MPAndroidChart) (0) | 2022.05.10 |
[스프링 / spring] 비밀번호 처리하기 (비밀번호 확인,변경) (0) | 2022.05.04 |
[안드로이드 / android] 달력 라이브러리( prolificinteractive/material-calendarview ) (0) | 2022.05.03 |