2012-03-16 35 views
7

Tôi có một nút phong cách tùy chỉnh như sau:Kế thừa drawable selector

<?xml version="1.0" encoding="utf-8"?> 
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item android:state_checked="true" > 
    <shape> 
     <gradient 
      android:startColor="@color/Shadow" 
      android:endColor="@color/Highlight" 
      android:angle="270" /> 
     <stroke 
      android:width="1dp" 
      android:color="#000" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

<item android:state_pressed="true" > 
    <shape> 
     <gradient 
      android:startColor="@color/Shadow" 
      android:endColor="@color/Highlight" 
      android:angle="270" /> 
     <stroke 
      android:width="1dp" 
      android:color="#000" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

<item>   
    <shape> 
     <gradient 
      android:startColor="@color/Shadow" 
      android:endColor="@color/Highlight" 
      android:angle="90" /> 
     <stroke 
      android:width="1dp" 
      android:color="#000" /> 
     <corners 
      android:radius="50dp" /> 
     <padding 
      android:top="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 
</selector> 

bây giờ tôi muốn tạo ra một nút đó trông như thế này ngoại trừ các góc đúng không tròn. Tôi biết cách đặt bán kính góc riêng lẻ nhưng có cách nào để kế thừa tất cả các thuộc tính khác của nút tùy chỉnh của tôi không?

tôi đã cố gắng:

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
<item android:drawable="@drawable/custom_button"> 
    <shape> 
      <corners android:topRightRadius="0dp" 
       android:bottomRightRadius="0dp"/> 
     </shape> 
</item> 
</selector> 

nhưng thẻ góc của tôi dường như bị bỏ qua hoàn toàn, các nút chỉ trông giống như custom_button. Có suy nghĩ gì không?

Trả lời

1

<shape><corners> không chấp nhận thuộc tính kiểu nên tôi nghĩ bạn không thể làm được gì nhiều.