Button

Kotlin

ボタンのデザインをカスタマイズする

--- res/drawable/original_btn.xml ---

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="90"   <-- 上から下へ
        android:startColor="#ff5733"  <-- 開始色
        android:endColor="#ffc3000" />

    <corners
        android:radius="16dp" /> <-- 角丸

    <stroke
        android:color="@color/black"
        android:width="2dp"
</shape>

--- activity_main.xml ---
<Button
    android:background="@drawable/original_button" />

画像とテキストの入ったボタンをつくる

<androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/btnGoToCustomer"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:orientation=
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/tvNavHome" >
            <ImageView
                android:id="@+id/ivCustomerIcon"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:src="@drawable/customer"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/tvCustomerIcon"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>
            <TextView
                android:id="@+id/tvCustomerIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="お客様情報"
                android:textSize="10sp"
                app:layout_constraintTop_toBottomOf="@+id/ivCustomerIcon"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>
BACK