Android 波纹:其他应用程序如何在不影响视图原始颜色的情况下使它们的波纹如此透明
Android Ripple: How do other apps make their ripple so transparent without affecting the original colour of the view
当您查看 yPlan 或 Google Play Store 等其他应用时,它们对按钮的涟漪效果就像浅灰色或黑色,不会改变整个按钮的颜色。
我想要同样的效果。
这是我试过的,但不一样
这是我的颜色控制亮点:它是 99% alpha 的灰色
<color name="colorHighlight">#fc8c969f</color>
这是我的按钮波纹抽屉
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white"/>
<item android:drawable="@color/colorAccentWith92PercentOpacity"/>
</ripple>
请注意,drawable 是将按钮的颜色设为黄色,因为我不能使用 android:background 两次
<?xml version="1.0" encoding="utf-8"?>
<!--Use an almost transparent color for the ripple itself-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#22000000">
<!--Use this to define the shape of the ripple effect (rectangle, oval, ring or line). The color specified here isn't used anyway-->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!--This is the background for your button-->
<item>
<!--Use the shape you want here-->
<shape android:shape="rectangle">
<!--Use the solid tag to define the background color you want (here yellow)-->
<solid android:color="#ffff00"/>
<!--Use the stroke tag for a border-->
<stroke android:width="1dp" android:color="#ffff00"/>
</shape>
</item>
</ripple>
当您查看 yPlan 或 Google Play Store 等其他应用时,它们对按钮的涟漪效果就像浅灰色或黑色,不会改变整个按钮的颜色。
我想要同样的效果。
这是我试过的,但不一样
这是我的颜色控制亮点:它是 99% alpha 的灰色
<color name="colorHighlight">#fc8c969f</color>
这是我的按钮波纹抽屉
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white"/>
<item android:drawable="@color/colorAccentWith92PercentOpacity"/>
</ripple>
请注意,drawable 是将按钮的颜色设为黄色,因为我不能使用 android:background 两次
<?xml version="1.0" encoding="utf-8"?>
<!--Use an almost transparent color for the ripple itself-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#22000000">
<!--Use this to define the shape of the ripple effect (rectangle, oval, ring or line). The color specified here isn't used anyway-->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!--This is the background for your button-->
<item>
<!--Use the shape you want here-->
<shape android:shape="rectangle">
<!--Use the solid tag to define the background color you want (here yellow)-->
<solid android:color="#ffff00"/>
<!--Use the stroke tag for a border-->
<stroke android:width="1dp" android:color="#ffff00"/>
</shape>
</item>
</ripple>