外形上大号的Andr​​oid触摸涟漪效应? [英] Android L ripple touch effect on shape?

查看:118
本文介绍了外形上大号的Andr​​oid触摸涟漪效应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个圆角矩形与升华,蒙上了一层阴影,就像在这里的例子:<一href="http://developer.android.com/$p$pview/material/views-shadows.html#shadows">http://developer.android.com/$p$pview/material/views-shadows.html#shadows

I have a rounded rectangle with elevation that casts a shadow, just like in the example here: http://developer.android.com/preview/material/views-shadows.html#shadows

下面是我的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white" />
    <corners android:radius="6dp" />
</shape>

我想获得不错的涟漪的触摸效果一切了,但是当这样设置视图的背景,没有触摸反馈给。形状保持白色。

I want to get the nice "ripple" touch effect that everything else has, but when that's set as the view's background, no touch feedback is given. The shape stays white.

所以,我把它做成了图层列表

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:radius="6dp" />
        </shape>
    </item>
    <item android:drawable="?android:selectableItemBackground" />
</layer-list>

现在我得到的,当我点击它很好的接触反馈,但有一个问题。

Now I get nice touch feedback when I tap it, but there's a problem.

圆角矩形形状的轮廓丢失。它仍然吸引了白色的圆角矩形正常,但投下阴影作为非圆角矩形(直角边缘),纹波去一路走出过去的角落:

The outline of the rounded rectangle shape was lost. It still draws the white rounded rectangle fine, but the shadow is cast as a non-rounded rectangle (square edges), and the ripple goes all the way out past the corners:

它看起来并不对这里太恐怖了,但在设备上是pretty的丑陋和倒胃口。

It doesn't look too horrible on here, but on the device it's pretty ugly and off-putting.

有没有办法来解决这个问题?第一个链接的大纲部分似乎正是我想要的,但我不能想出如何实现它。

Is there a way to fix this? The Outline section of the first link seems to be what I want, but I can't figure out how to implement it.

推荐答案

试着说一句:

ripple.xml

ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple android:color="@color/COLOR_WHILE_PRESSING" xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/background"></item>
</ripple>

background.xml

background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <solid android:color="@color/BACKGROUND_COLOR" />
 <corners android:radius="6dp" />
</shape>

或者,也许这篇文章将帮助你:<一href="http://stackoverflow.com/questions/24480425/android-l-fab-button-shadow/24498041#24498041">Android大号FAB按钮阴影

我解释过,如何实现新的FAB按钮,我还使用了大纲的。

I explained there, how to implement the new FAB button, I also used the outline for that.

这篇关于外形上大号的Andr​​oid触摸涟漪效应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆