안드로이드 공부

[안드로이드 스튜디오] button 색상 변경 안 될 때

코메인 2022. 8. 9. 21:47

안녕하세요~ 코딩하는 코알못 코메인입니다.

안드로이드 스튜디오에서 Button을 사용할때 background를 설정 했어도 정작 디바이스에서는 변경되지 않는 경우가 있다. 그런 경우 해결 방법에 대해 알아보겠다.

 

어려운 것 없이 단 하나만 바꿔주면 된다.

사용 방법

xml에서 색상 변경(background 적용)이 되지 않는 Button의 이름을 android.widget.Button으로 바꿔주면 된다.

 

코드

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="131dp"
        tools:layout_editor_absoluteY="182dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

 

해당 xml에서 <Button을 <android.widget.Button으로 바꿔주자.

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    
    <android.widget.Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="131dp"
        tools:layout_editor_absoluteY="182dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

 

보시는 분들에게 도움이 되셧으면 좋겠고, 만약 보시고 틀린 점이나 추가로 정보를 주고 싶은 분이 있다면 거리낌 없이 댓글로 남겨주시면 감사히 새겨 듣겠습니다.