티스토리 뷰

얼마 전에 팀프로젝트로 하고 있는 앱을 데모로 만들었는데 테스트 해보다가 커서 색이랑 하이라이트 되는 색깔을 바꾸고 싶어서 열심히 구글링을 해보았다. 간단하게 찾을 수 있을 것 같았는데 여러 방법이 나오고 생각보다 안되는것도 많아서 여러가지를 고민해보았다. 

 

 

맘에 안들었던 문제의 그 사진

 

 

핑크색은 예쁘지만 전체 테마가 노란색이기 때문에 하이라이트랑 커서랑 다 핑크인게 싫었다.

이 핑크의 출처를 알아보자면

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@color/colorStatus</item>
</style>

 

여기에 기원이 있다.  colorAccent값이 저 핑크색인데 내가 아무 스타일도 정해주지 않으면 디폴트로 저 "AppTheme"이란 친구의 스타일을 따라간다. 그래서 저 커서색이랑 하이라이트 되는 색이 핑크색인 것이다.

여기서 야매인 방법을 발견했는데 내가 생각하기에 가장 간편한 방법인데 정답인지는 모르겠다 ㅎ_ㅎ

 

 


 

EditText 커서색/밑줄 하이라이트색 바꾸기

 

 STEP1. values-res-colors.xml

<color name="cursorColor">#ffb65d</color>
<color name="nomalColor">#ffcd54</color>

 

STEP2. values-res-style.xml

<style name="EditTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/cursorColor</item>
</style>

 

위에서 colorAccent로 커서 색이랑 하이라이트 색이 핑크로 변했기 때문에 EditTheme이란 이름으로 style을 추가했다.

액션바가 없는 걸 원해서 NoActionBar를 선택했고 colorAccent값을 cursorColor라는 노란색 컬러로 바꾸었다.

 

 

STEP3. 해당 xml에 아래 코드 추가

android:theme="@style/EditTheme"

 

 

<실행 결과>

 


 

EditText 기본 밑줄 색 바꾸기

 

커서와 하이라이트 색 외에 editText 밑줄 색, 하이라이트 시 editText 밑줄 색 등을 지정할 수 있다.

- colorAccent: 커서색, 드래그 시 하이라이트 색, eidtText선택 시 밑줄 하이라이트 색 등 강조 색을 변경

- colorControlNormal: 하이라이트 되지 않았을 때 밑줄 색

<style name="EditTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/cursorColor</item>
<item name="colorControlNormal">@color/nomalColor</item>
</style>

 

 

<실행 결과> 제목 옆 editText색 변경

 

 

 

 


 

+ 추가 내용

 

하나의 xml이 아니라 전체 xml에 적용하고 싶을 때

 

위의 EditTheme에서 했던 작업들을 AppTheme에서 바꿔주면 된다

 

 

 

밑줄 없애기(xml)

android:background="@null"

 

커서 색만 바꾸기(xml)

 

drawable-cursor.xml 생성

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ffb65d"
android:endColor="#ffb65d"/>
</shape>

 

자신이 바꾸고 싶은 xml에 해당 EditText에 textCursorDrawable="@drawable/파일 이름" 추가

   <EditText
android:id="@+id/edit_receiver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textCursorDrawable="@drawable/cursor"
android:layout_toRightOf="@+id/text_receiver" />
</RelativeLayout>

'안드로이드' 카테고리의 다른 글

[안드로이드] 스플래시(Splash) 만들기  (0) 2018.05.12
최근에 올라온 글
Total
Today
Yesterday