使用shape可以自定义xml颜色
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#88CCCCCC" /> 
    <corners android:topLeftRadius="15dp" android:topRightRadius="15dp"
             android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp"/> 
</shape>
但是一直无法实现分层色,如上图效果,有没有不使用img直接写出xml的方式,不需要完全一样。差不多就行,因为用图片修改主题色不方便。求大神回答AndroidXMLdrawable自定义样式

解决方案 »

  1.   

    <?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
         <gradient
            android:startColor="#0066ff"
            android:centerColor="#0066ff"
            android:endColor="#004AAD"
            android:angle="-90" />
        <corners android:radius="15dp"/> 
    </shape>上面这样也只能实现中间一个颜色,颜色是渐变的,不是分块的,怎么实现如上图上下两种颜色的button?
      

  2.   

    这个应该可以,xml实现的圆角矩阵,但是不是渐变的
    <?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="#dddddd"
             />  
                <corners 
                    android:radius="5dip"
                    />
            </shape>  
        </item>  
          
        <item  
            android:top="2px"
            android:left="2px"
            android:right="2px"
            android:bottom="2px">  
            <shape android:shape="rectangle">  
                <solid 
                    android:color="#FFFFFF" 
                    />  
                <corners
                    android:radius="5dip"
                    />
            </shape>
        </item>  
     </layer-list>