くらげになりたい。

くらげのようにふわふわ生きたい日曜プログラマなブログ。趣味の備忘録です。

AndroidでMaterial Designボタンに変更するスタイル

Androidアプリを作っていて、マテリアルデザインのボタンにしたいなと思い、色々調べた備忘録。

Raised Button

f:id:wannabe-jellyfish:20170729233133p:plain

styles.xmlにスタイルを用意する

用意するスタイルはこんな感じ。

<style name="AppTheme.RaisedButton" parent="Theme.AppCompat.Light">
    <item name="colorControlHighlight">#FFD464</item>
    <item name="colorButtonNormal">#FBA848</item>
    <item name="android:textColor">#FFFFFF</item>
</style>

Buttonにスタイルを適用

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Raised Button" 
    android:theme="@style/AppTheme.RaisedButton"
    />

Flat Button

f:id:wannabe-jellyfish:20170729234307p:plain

styles.xmlにスタイルを用意する

用意するスタイルはこんな感じ。

<style name="AppTheme.FlatButton" parent="Theme.AppCompat.Light">
    <item name="colorControlHighlight">#FFD464</item>
    <item name="android:textColor">#FBA848</item>
</style>

Buttonにスタイルを適用

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Flat Button"
    android:theme="@style/AppTheme.FlatButton"
    style="@style/Widget.AppCompat.Button.Borderless"
    />

以上!!

参考にしたサイト様