24
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

お手軽にタッチフィードバックをもった drawable リソースを構築する

Last updated at Posted at 2015-07-07

注意:この Tips は Lollipop でのみうまく動きます。

Android の標準のテーマで、以下の属性が定義されていて、OS のバージョンごとタッチフィードバックが StateListDrawable になっている。

selectableItemBackground

これを使うことで、自分で StateListDrawable を作らなくても、ある程度デフォルトの見た目のタッチフィードバックが構築できる。

例えば、以下のような LayerListDrawable を定義することで、好きな色の上にタッチフィードバックを乗せることが出来る。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="#232323"/>
    </item>
    <item android:drawable="?attr/selectableItemBackground"/>
</layer-list>

Lollipop の Ripple Effect が好きな色の上に乗ってくれて便利です。

24
26
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
24
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?