LoginSignup
0
1

More than 3 years have passed since last update.

AndroidのボタンUIを角丸にしたい

Last updated at Posted at 2021-04-10

画面デザイン資料をもらった時、ボタンUIが角丸で枠線が付いていた為、次のような対応を行った。

リソースのlayout

まずはlayoutファイルにButtonを配置。

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:textColor="#ffffffff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
リソースのdrawable

つぎにshapeを使ったdrawableファイルを作成。

button_style.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dip" />
    <solid android:color="#ff262626" />
    <stroke
        android:width="1dp"
        android:color="#ffffffff" />
</shape>
作成したdrawableをlayoutに適用

Buttonのbackground属性に作成したdrawableを設定する。

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:textColor="#ffffffff"
        android:background="@drawable/button_style"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
イメージ

image.png

0
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
0
1