在背景的XML之外指定按钮的背景形状颜色 [英] Specify Button's Background Shape Color Outside of the Background's XML

查看:75
本文介绍了在背景的XML之外指定按钮的背景形状颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Button ,它使用形状作为背景.

I have a Button that uses a shape as it's background.

根据按钮

我是否可以在 Button 的xml中指定每个状态的颜色?对于新手问题,我感到抱歉.有指导吗?

Is it possible for me to specify the color of each state inside the Button's xml? I am sorry for the newbie question. Any guide please?

button_background.xml

button_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <solid android:color="@color/colorWhite" />
        </shape>
    </item>
</selector>

目前的称呼方式

    <Button
        android:id="@+id/loginButton"
        android:background="@drawable/button_background"
        android:text="@string/login_button_title"/>

推荐答案

这是一个较晚的答案,但是我在

This is a bit of a late answer, but I described what you want in detail in this post, even how to produce ripples in your background, you might want to check it out

这篇关于在背景的XML之外指定按钮的背景形状颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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