Android L's Ripple Effect - Touch Feedback for Buttons - Using XML

前端 未结 7 1680
青春惊慌失措
青春惊慌失措 2020-11-27 11:13

I am trying to understand how to implement the \"Ripple Effect - Touch Feedback\" for buttons and other views. I looked at the questions related to Ripple touch effect on SO

7条回答
  •  误落风尘
    2020-11-27 12:06

    I was researching ripple effect as it was something I wanted to apply to a few buttons in my application and happened across your post. While your question is searching for an answer as to how to add the ripple effect using XML that was actually something I was trying to avoid as when trying to add that attribute you see it requires v21.

    If you are targeting lower than v21 than that new class extending Button (or ImageButton, etc.) will avoid complaints from the compiler.

    As there was no explanation on how to implement the custom class above I thought I would fill in. All you need to do is create the new class and then in the XML change "Button" to "the.package.name.MyButton".

    From:

     

    To:

     
    

    That's it. Now your button when pressed will have a ripple contained within its bounds.

    I like this approach I just wish the ripple would extend pass the bounds. For a small button this ripple effect really highlights how square or rectangular the button really is. Visually it would be more satisfying if the ripple just continued until it reached its full radius.

提交回复
热议问题