如何设置按钮颜色 [英] how to set button color

查看:198
本文介绍了如何设置按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样

<shape      xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

<solid   android:color="#EAEAEA"/>

<corners    android:topLeftRadius="8dip"
            android:bottomRightRadius="8dip"
            android:bottomLeftRadius="1dip"
            android:topRightRadius="1dip"
            />
<item android:drawable="@drawable/photo2"
      android:state_pressed="true" />
<item android:drawable="@drawable/photo1" />

<item android:drawable="@drawable/photo2"
      android:state_pressed="true" />
<item android:drawable="@drawable/photo1" />

这是行不通的(如果它工作,它昌按钮时,研究背景preSS或取消preSS按钮)

it doesn't work ( if it work it will chang button backgroud when press or un press button )

我应该怎么办?

推荐答案

首先导入 LightningColorFilter ,那么你可以通过应用此code改变颜色:

First Import LightningColorFilter, then you can change the color by applying this code:

Start_Button.getBackground()setColorFilter(新LightingColorFilter(0x11111111,0x11111111));

这是放置你的活性的研究里面,而不是XML文件。

This is to be placed inside your acitivity, and not the XML file.

这篇关于如何设置按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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