Chef.Yeon
Code Cook
Chef.Yeon
전체 방문자
오늘
어제
  • 분류 전체보기 (230)
    • 게임 개발 (1)
      • Unity (1)
    • Android (27)
      • Kotlin (19)
      • 우아한테크코스 5기 (4)
    • Language (11)
      • 파이썬 (3)
      • Java (7)
    • DB (2)
      • SQL (16)
    • Spring (25)
    • 코딩테스트 (56)
    • Git (1)
    • TIL (85)
    • DevOps (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • spring
  • SQL
  • 프로그래머스
  • 내림차순
  • 우아한테크코스
  • 다이나믹 프로그래밍
  • 프리코스
  • 레포지토리
  • 백준
  • 코틀린
  • java
  • enum
  • 코딩테스트
  • rsocket
  • ec2
  • 에라토스테네스의 체
  • 문자열
  • Android
  • 안드로이드
  • kibana
  • elasticsearch
  • til
  • Wil
  • kotlin
  • 코틀린 인 액션
  • grafana
  • webflux
  • 파이썬
  • Docker
  • MariaDB

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Chef.Yeon

Code Cook

Android

[Android/Kotlin] 버튼 Background 설정 시, 색상이 적용되지 않는 문제 해결 방법

2022. 12. 29. 21:47
728x90

❓ 문제 상황

EditText와 Button의 모양을 바꾸기 위해 res > drawble 폴더에 rounded_corner_rectangle.xml 파일을 생성해서 다음과 같은 코드를 작성했습니다.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:thickness="0dp">
    <corners android:radius="8dp" />
    <padding
        android:bottom="5dp"
        android:left="35dp"
        android:right="35dp"
        android:top="5dp" />
    <size android:height="45dp"/>
</shape>

 

editText와 Button의 배경색은 다르게 지정할 것이므로 activity_main.xml 파일에서 EditText와 Button에 따로 지정해주었습니다. 위에서 만든 둥근 테두리를 적용하기 위해 android:background="@drawble/rounded_corner_rectangle" 을 사용하여 설정해주었습니다.

<EditText
    android:id="@+id/passwordEditText"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/rounded_corner_rectangle"
    android:backgroundTint="@color/grey"
    android:hint="password"
    android:inputType="textPassword"
    android:singleLine="true"
    android:textSize="16sp"
    app:layout_constraintEnd_toEndOf="@id/loginImageView"
    app:layout_constraintStart_toStartOf="@id/loginImageView"
    app:layout_constraintTop_toBottomOf="@id/idEditText" />

<Button
    android:id="@+id/loginButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:background="@drawable/rounded_corner_rectangle"
    android:backgroundTint="@color/blue"
    android:text="LOGIN"
    android:textColor="@color/white"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="@id/loginImageView"
    app:layout_constraintStart_toStartOf="@id/loginImageView"
    app:layout_constraintTop_toBottomOf="@id/passwordEditText" />

EditText에서는 backgroundTint를 grey로 설정했을 때 정상적으로 변경이 되나, Button은 blue 색상이 적용되지 않는 문제가 발생했습니다.

 

 

💡 해결 방안

res > themes > themes.xml 파일로 갑니다. 여기서 Theme.MaterialComponents.DayNight라고 작성되어 있는 것을 보실 수 있습니다. 

<style name="Theme.2DoList" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

 

MaterialComponents 부분을 AppCompat으로 변경하면 Button에 backgroundTint 색상이 제대로 적용되는 것을 확인할 수 있습니다.

<style name="Theme.2DoList" parent="Theme.AppCompat.DayNight.DarkActionBar">

728x90

'Android' 카테고리의 다른 글

[Android] Activity와 Lifecycle (생명 주기)  (0) 2022.12.23
[안드로이드 스튜디오] Execution failed for task ':app:checkDebugAarMetadata'  (0) 2022.10.19
[안드로이드 스튜디오] Github 저장소 생성 & Android 프로젝트 연동/깃허브 토큰 로그인  (0) 2022.09.29
    'Android' 카테고리의 다른 글
    • [Android] Activity와 Lifecycle (생명 주기)
    • [안드로이드 스튜디오] Execution failed for task ':app:checkDebugAarMetadata'
    • [안드로이드 스튜디오] Github 저장소 생성 & Android 프로젝트 연동/깃허브 토큰 로그인
    Chef.Yeon
    Chef.Yeon
    보기 좋고 깔끔한 코드를 요리하기 위해 노력하고 있습니다.

    티스토리툴바