情報は力ではない

UE4 とか Blender とか。

ImageButtonを使ってみた。

f:id:masahiro8080:20151116140122p:plain:w400
上の画像の再生ボタンのようなボタンを作成したかったので、そのためのメモ。

ImageButton

このようなボタンを作成するためにはImageButtonを使う。これは、その名の通り画像付きのボタンを表す。
例えばこんな感じに表示される。
f:id:masahiro8080:20151116141416p:plain:w400
このImageButtonの結果は次のようなコードで得られる。

...
    <ImageButton
        android:id="@+id/click_me_button"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/click_me"
        android:tint="@color/colorAccent"
        android:src="@drawable/ic_action_playback_play" />
...

見ての通り、通常のButtonにtextの代わりに画像を載せた感じになっている。
最初の画像のように背景を透過させたい場合には、ImageButtonのandroid:background属性にアルファ値がffの値を指定してあげれば良い。
ただ、これだとボタンをクリックした時にボタンが何も反応していないような感じになってしまうので、android:background属性には?android:selectableItemBackgroundや?android:selectableItemBackgroundBorderlessを指定してあげるとボタンをクリックした時に波紋が広がるようなアニメーションが得られる。
これを行うことで次のようにボタンの背景が透過されて表示される。
f:id:masahiro8080:20151116142651p:plain:w400

感想

Android開発では色々と学ぶことが多いので大変だけど、それなりに充実しているので、どんどん学んでいきたい。