안드로이드

[Android] Button에 background drawable 적용 안 되는 문제 해결

먹구루미 2024. 3. 22. 20:06

✏️ TIL(Today I Learned)

Selector를 사용하려고 Button에 background 속성을 추가했지만 버튼의 디자인 바뀌지 않는 문제가 발생했다. 따로 오류가 발생하는 것도 아니어서 뭐가 문제인지 알 수 없었다.

 

그래서 검색을 하며 찾아보니 res/values/themes/themes.xml 에서 style 때문이었다.

 

MaterialComponents를 상속받고 있는데, MaterialComponents가 Background를 자체적으로 갖고 있기 때문에 background를 지정해도 변경되지 않는 것이다. 그래서 아래와 같이 코드를 수정하면 background가 적용된다.

parent="Theme.AppCompat.Light"

 

이 방법이 싫다면 단순히 Button을 android.widget.Button 또는 androidx.appcompat.widget.AppCompatButton 으로 바꾸는 수도 있다.