LoginSignup
1
1

More than 1 year has passed since last update.

ボタンの角を丸くする方法

Last updated at Posted at 2022-03-13

ボタンの角を丸めたいという時ありますよね。
丸める方法が少し複雑だったのでまとめておきます。

完成画像

ここでは左下と右上の角を丸くしていきます。
名称未設定.png

手順

①ファイルを作る

Android > app > res > valuesに、shape.xmlファイルを作る必要があります。
このファイルの中に、角の情報を入力していきます。

②角の情報を入力する

それぞれの角の角度を入力します。
今回はマテリアルデザインのボタンを使用しているので、
parentは「ShapeAppearance.MaterialComponents」になっています。
それぞれの状況に合わせてparentは変更してください。

shape.xml
<resources>

    <style name="ShapeAppearance.Sunflower.Button.Add" parent="ShapeAppearance.MaterialComponents">
        <item name="cornerFamily">rounded</item>

        <item name="cornerSizeTopLeft">0dp</item>
        <item name="cornerSizeTopRight">@dimen/button_corner_radius</item>
        <item name="cornerSizeBottomRight">0dp</item>
        <item name="cornerSizeBottomLeft">@dimen/button_corner_radius</item>
    </style>

    <dimen name="button_corner_radius">12dp</dimen>


</resources>

レイアウトに追加する

app:shapeAppearance="@style/ShapeAppearance.Sunflower.Button.Add"/>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1