Androidのボタンに枠線を付ける方法

Androidのボタンに枠線を付ける方法です。
OutlinedButtonを使えば簡単なのですが、そこに気付かずにハマってしまいました。。

hoge.xml

1
2
3
4
5
6
<com.google.android.material.button.MaterialButton
android:id="@+id/hoge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/HogeButton" />

styles.xml

1
2
3
4
5
6
7
8
9
10
11
<style name="HogeButton" parent="Widget.Material3.Button.OutlinedButton">
<item name="android:layout_marginLeft">7dp</item>
<item name="android:layout_marginRight">7dp</item>
<item name="android:paddingTop">17dp</item>
<item name="android:paddingBottom">17dp</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="cornerRadius">3dp</item>
<item name="strokeWidth">2dp</item>
<item name="strokeColor">#EDA844</item>
</style>

Androidのボタンに枠線を付ける方法

https://reon777.com/2022/06/10/android-button-stroke/

Author

reon777

Posted on

2022-06-10

Updated on

2026-06-30

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×