230807 TIL

장재용·2023년 8월 7일

TIL

목록 보기
11/32

Color나 String은 하드코딩을 자제하자.

String은 번역을 위한 이유가 크고
color는 일일히 컬러를 바꾸는것보다 colors.xml파일에서 코드 한번 수정하면 그것을 참조하고 있는 모든 위젯의 컬러가 바뀌므로 훨씬 효율적이다.

버튼 selector로 버튼 눌렀을때 변화 주기

res -> drawable 마우스 오른쪽 -> new -> Drawable Resource File

Selector 태그 밑에 item 태그 2개를 만들어 state_pressed와 default시 버튼 디자인을 해준다.

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"> // 버튼 눌렀을때 버튼 상태
        <shape android:shape="rectangle">
                <solid android:color="#FA58F4"/>
                <corners android:radius="15dp"/> // 모서리 깎아서 둥글게 만들려는 용도
        </shape>
    </item>
    
    <item>
        <shape android:shape="rectangle"> // 평상시 버튼 상태
                <solid android:color="#FFFF00"/>
                <corners android:radius="15dp"/>
        </shape>
    </item>

</selector>

xml코드에서 버튼의 바꾸고자 하는 부분에 셀렉터xml로 연결해준다.

<ImageView
	android:id="@+id/imageView4"
    android:layout_width="55dp"
    android:layout_height="46dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.322"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    
    app:srcCompat = "@drawable/picture_selector"
    />

추가 Selector 공부하기 좋은 링크

https://aries574.tistory.com/234

EditText 위젯의 hint에 색상 주기

1. hint 색상 변경

android:textColorHint = "#123456"

2. hint 글자 크기 변경

android:textSize = "15sp"

hint 사이즈는 텍스트 사이즈를 따라간다.

profile
enjoy_error_message!

0개의 댓글