마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

버튼의 색상과 테두리를 동시에 변경하는 방법

0 추천

일정하게 둥근 모양이지만 각각 색이 다른 버튼 6개를 배치하고 싶은데, background와 backgroundTint에 미리 drawable로 값을 지정한 변수를 설정했더니 버튼 색이 계속 검정색으로 유지가 되네요.. 

계속 둥근 모양의 버튼을 사용할 생각이어서 drawable파일에 미리 둥근 모양의 <corners android:radius="18dp"> 값만 주었는데, main xml코드에서 모양과 색상을 동시에 변경할 수는 없는 걸까요?

android:background="@drawable/btn_rounded"
android:backgroundTint="@color/energy_yellow"
개발탈출 (210 포인트) 님이 2023년 1월 8일 질문

1개의 답변

0 추천
 
채택된 답변
Material design을 이용해서 Shape theming + Button styling을 사용하시면 되지 않을까요?

https://m2.material.io/develop/android/theming/shape

https://github.com/material-components/material-components-android/blob/master/docs/components/Button.md

https://m2.material.io/components/buttons/android#text-button

Matrieal theme을 사용하는 것이 더 권장하는 방식이지만, selector를 사용할 수도 있습니다.

https://www.digitalocean.com/community/tutorials/android-button-design-custom-round-color
spark (224,800 포인트) 님이 2023년 1월 9일 답변
개발탈출님이 2023년 1월 11일 채택됨
...