背景Android的纹波按钮 [英] android ripple button with background

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

问题描述

我成功地使用XML创建了的是Android 5.0波纹按钮。我的code是如下:

I successfully created a ripple button in android 5.0 using XML. My code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- the flat button to be used in app -->
<!-- define the ripple -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <!-- the ripple object -->
    <item android:id="@android:id/mask">
        <!-- button shape (w/ radius) -->
        <shape android:shape="rectangle">
            <!-- radius of vertices -->
            <corners
                android:topLeftRadius="7dp"
                android:topRightRadius="7dp"
                android:bottomLeftRadius="7dp"
                android:bottomRightRadius="7dp" />
            <!-- color accent (not working) -->
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>

我与按钮一个问题:按钮的背景颜色不会改变。我也曾尝试:

I have a problem with the button: the background color of the button won't change. I have also tried:

<solid android:color="#0000ff" />

背景仍然继续保持透明(在colorAccent也不会被工作)。

The background still continues to stay transparent (the colorAccent isn't working either).

我应该如何去通过矩形的(按钮的)背景如果没有设置为蓝色

How should I go about setting the rectangle's (the button's) background to blue if not through the

<solid/>

属性?

感谢

推荐答案

使用 @android:ID /掩码标识设置图层作为掩模,它仅用于用于裁剪边界和不绘制。删除id属性应该给你你在找什么。另外,你可以使用的android:半径属性,如果弯道都是相同的半径

Using the @android:id/mask identifier sets the layer as a mask, which is only used for clipping bounds and is not drawn. Removing the id attribute should give you what you're looking for. Also, you can just use the android:radius attribute if the corners are all the same radius.

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:attr/colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="7dp" />
            <solid android:color="?android:attr/colorAccent" />
        </shape>
    </item>
</ripple>

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

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