2011-05-31 102 views
2

我想这样如何设置按钮颜色

<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" /> 

它不工作(如果它工作,它昌按钮时,研究背景按或不按按钮)

我该怎么办?

回答

4

首次进口LightningColorFilter,则可以通过应用此代码改变颜色:

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

这是放置你的胡亚蓉里面,而不是XML文件。

+0

它强制关闭。 – user65544 2011-05-31 10:14:23

+0

你会用这个来代替一个可绘制的图像。 – Navigatron 2011-05-31 10:30:54

+0

如何将其设置回默认按钮颜色? – powder366 2013-06-25 18:10:43

1

设置样式和颜色为默认按钮,在任何新的XML设置此代码,并给orgnal按钮背景为这个XML这样的:

在一部开拓创新的按键布局XML

: - 的Andorid:背景=“@绘制/ mylayout”

在mylayout.xml: -

<item android:state_pressed="true" > 
    <shape> 
     <gradient 
      android:startColor="@color/yellow1" 
      android:endColor="@color/yellow2" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      android:color="@color/grey05" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

<item android:state_focused="true" > 
    <shape> 
     <gradient 
      android:endColor="@color/orange4" 
      android:startColor="@color/orange5" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      android:color="@color/grey05" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

<item>   
    <shape> 
     <gradient 
      android:endColor="@color/blue2" 
      android:startColor="@color/blue25" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      android:color="@color/grey05" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

,并改变对焦按钮或点击事件尝试设置onfocuschnage其他布局:

<item android:state_focused="true" > 

,并设置不同势颜色更改按钮颜色或样式..

相关问题