LoginSignup
18
15

More than 5 years have passed since last update.

RippleEffectのXML書くのめんどくさい人へ

Posted at

小ネタです。割と知らない人いるかも

RippleEffectつけてますか?Android 5.0以降でぽわ~んって波紋でるやつです。
Material Design的には重要な要素ですが色どうすればいいんだ!とか悩みますよね。
デザイナーさんもあんま指定しないし勝手に色決めてる人多いのでは?w

実は標準で用意されてる

実はAndroid標準で用意されていて、Android 4.x系でも非RippleEffectながらタップ色が変わるエフェクトがちゃんと動作します。

やり方はSupport Libraryをインポートして↓をViewに指定するだけ。簡単ですね。

activity.xml
<LinearLayout
    android:background="?attr/selectableItemBackground"/>

ちなみにCardViewの時はandroid:foregroundに指定すればオッケーです。

また、以下のBorderlessを指定すれば親レイアウト(この場合だとLinearLayout)の境界をはみ出してある程度のサイズまでRippleEffectが広がります。

activity.xml
<LinearLayout
    android:background="?attr/selectableItemBackgroundBorderless"/>

以下のようなボーダーレスなボタンを置く時が使いドコロですかね
components_menus_usage4a.png

18
15
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
18
15