Android的波纹背景颜色 [英] Android ripple background color

查看:232
本文介绍了Android的波纹背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的导航抽屉产生连锁反应。我曾经这样设置,它应用到我的ListView:

I am using a ripple effect on my navigation drawer. I have set it like this and applied it to my ListView:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@color/black_200" />

    <item android:state_pressed="true" android:color="@color/black_200">
        <ripple android:color="@color/black_400" />
    </item>

    <item android:drawable="@color/white" />
</selector>

我想纹波背景仍然像正常激活状态相同。甚至当我定义的颜色是一样的激活状态,它就会变暗,且波纹泡沫会变得更加黑暗。我怎样才能颜色背景是一样的,如激活状态,纹波泡沫要我告诉它的颜色是?

I want the ripple background to remain the same like the normal activated state. Even when I define the color to be the same as the activated state, it gets darker and the ripple bubble gets even more dark. How can I color the background to be the same like the activated state and the ripple bubble to be the color I told it to be?

推荐答案

您可以通过执行控制 RippleDrawable 的颜色如下:

You can control the colour of the RippleDrawable by doing the following:

RippleDrawable rippleDrawable = (RippleDrawable)view.getBackground(); // assumes bg is a RippleDrawable

int[][] states = new int[][] { new int[] { android.R.attr.state_enabled} };
int[] colors = new int[] { Color.BLUE }; // sets the ripple color to blue

ColorStateList colorStateList = new ColorStateList(states, colors);
rippleDrawable.setColor(colorStateList);

或者,通过XML:

<?xml version="1.0" encoding="utf-8"?>
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#FFFF0000"> <!-- The ripple will be red -->

    <!-- the normal bg color will be light grey -->
    <item>
        <color android:color="#FFDDDDDD" />
    </item>

    <!-- make sure the ripple doesn't exceed the bounds -->
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>

这篇关于Android的波纹背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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