LoginSignup
0
1

More than 1 year has passed since last update.

Drawableに2色の異なる色を描画する方法

Posted at

こんにちはandroidでアプリ開発を学習中のみのむしと申します。
今回は、Drawableの中に2色表示を行うボタンを描画しましたので、
作成方法等を備忘録として残したいと思います。

1.円形2色ボタンの作り方

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90">
    <shape
        android:shape="oval"
        >
        <gradient
            android:centerX="-10.0"
            android:endColor="#33B5E5"
            android:startColor="#EA578A"
            android:type="sweep" />
    </shape>

</rotate>

キータ円形.png
↑このように表示されます

2.四角2色ボタンの作り方

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90">
    <shape>
        <gradient
            android:centerX="-10.0"
            android:endColor="#33B5E5"
            android:startColor="#EA578A"
            android:type="sweep" />
    </shape>

</rotate>

キータ四角.png
↑このように表示されます

後は、配置したボタンなどやViewなどにandroid:background="@drawable/作成したファイル名を"入れればOKです。

参考サイト
https://stackoverflow.com/questions/38126248/how-to-create-android-drawable-consisting-of-two-colors-side-by-side

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