와챠의 우당탕탕 코딩 일기장

[Android/Kotlin]EditText scollbar custom/cursor color 본문

코딩 일기장/Android(Kotlin)

[Android/Kotlin]EditText scollbar custom/cursor color

minWachya 2022. 3. 19. 14:07
반응형

아래 UI는 "둥네 고영희" 앱 UI입니다!

 

기본: cursor color: 갈색
3줄 이상 썼을 때 커스텀 스크롤바 보이기

 

res>drawable>custom_scrollbar.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/beige_BBB5A4"/>
    <corners android:radius="66dp" />
    <size android:width="3dp"/>
</shape>

 

이 xml를 스크롤바를 붙이고 싶은 EditText에 붙이기

android:scrollbars="vertical"	// 세로로 스크롤
android:scrollbarThumbVertical="@drawable/custom_scrollbar"	// 커스텀한 스크롤바
android:maxLines="3"	// 최대 3줄까지 확장

 

그러면 요로코롬 됨

<EditText
    android:id="@+id/editPost"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_marginStart="20dp"
    android:layout_marginEnd="4dp"
    android:paddingTop="9dp"
    android:paddingEnd="8dp"
    android:scrollbars="vertical"
    android:scrollbarThumbVertical="@drawable/custom_scrollbar"
    android:maxLines="3"
    android:paddingStart="9dp"
    android:paddingBottom="7dp"
    android:background="@drawable/edit_line_round"
    android:fontFamily="@font/spoqa_han_sans_neo_regular"
    android:hint="@string/cat_detail_post_hint"
    android:textCursorDrawable="@drawable/edittext_cursor_color"
    android:textSize="14sp"
    app:layout_constraintEnd_toStartOf="@+id/btnPost"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvRecentPost" />

cursor 색 변경은:

android:textCursorDrawable="@drawable/edittext_cursor_color"

edittext_cursor_color.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="1dp" />
    <solid android:color="@color/brown_473A22"  />
</shape>

참고로... EditText 동글네모 테두리는 이거

android:background="@drawable/edit_line_round"

edit_line_round.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:color="@color/beige_E3DECF" android:width="1dp" />
    <corners android:radius="4dp" />
</shape>
반응형
Comments