2021. 1. 17. 21:20ㆍ카테고리 없음
버튼을 커스터 마이징 해서 테두리랑 이쁘게 만드려고 했다.
Button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<!--모형 지정 ex)직사각형 타원 등 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--배경색 -->
<solid android:color="#fff" ></solid>
<!--테두리 색 + 테두리 너비-->
<stroke
android:width="3dp"
android:color="#111" />
<!--꼭지점 휘는 각도-->
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp" />
</shape>
res-drawable에 resource파일을 만든 후 위와 같이 배경색 테두리 색 휘는 각도등을 지정해줘서 꾸미려고한 버튼으로 돌아와서 사용하려고 android:background="@drawable/button_background" 배경으로 지정해도 아무 변화가 없었다.
뭐가 문젤까 검색하다가 안드로이드 style에 Theme.MaterialComponents theme를 적용하면
Button을 커스터마이징 하는데 문제가 생긴다. 이것저것 검색하다가
https://stackoverflow.com/a/52673168/7017299
Can't use android:background with button from the new material components
I'm using the new material components com.google.android.material:material with android x but I can't set a custom background to the button. I know that I can use app:backgroundTint to change the ...
stackoverflow.com
자료를 보니 android.widget.Button 버튼을 사용하면 깔끔하게 해결이 되었다!
즉 머터리얼 버튼은 따로 배경을 가지고 있기 때문에 피해야한다는 소리다(androidx.appcompat.widget.AppCompatButton or android.widget.Button) 사용하기
다른 분들은 저처럼 삽질하지 않도록...