2011-09-22 76 views
3

我有一个状态列表如下:颜色状态列表+按钮上的形状?

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

</selector> 

而且这样的形状(四舍五入我的按钮):

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

我的问题是如何申请他们两个?如果我将backgroundResource设置为颜色列表,那么我会得到颜色,但是我无法将其用于形状。我尝试使用backgroundResource作为形状,而使用backgroundColor作为颜色,但这并不奏效。

回答

2
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_pressed="true" 
     android:drawable="@color/dark_green" > 
     <shape android:shape="rectangle"> 
      <corners android:bottomRightRadius="7dp" 
        android:bottomLeftRadius="7dp" 
        android:topLeftRadius="7dp" 
        android:topRightRadius="7dp"/> 
</shape> 
    <item/> 
    <item android:drawable="@color/bright_green" /> 
</selector> 

我已经做了类似your.but的东西,但是,它不起作用,当你使用你的dradwalbe。如果你这样使用(使用固体填充按钮不使用drawable,可以缩放圆形按钮),它可以工作。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
      <shape android:shape="rectangle"> 
     <solid android:color="#FFEC7600" /> 
     <corners 
         android:topLeftRadius="5dip" 
       android:topRightRadius="5dip" 
       android:bottomLeftRadius="5dip" 
       android:bottomRightRadius="5dip" /> 
     </shape> 
    </item>