结合按钮外观和重点色

时间:2019-06-16 20:52:51

标签: visual-studio xamarin xamarin.android

我有问题。我有2个xml文件: 第一个在聚焦按钮并按下时更改颜色:

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

  <item android:state_pressed="true" >
    <shape>
      <solid android:color="#318e3e" />
    </shape>
  </item>

  <item android:state_focused="true" >
    <shape>
      <solid android:color="#318e3e" />
    </shape>
  </item>

  <item>
    <shape>
      <solid android:color="#24c139" />
    </shape>
  </item>
</selector>

第二个只是改变按钮的外观:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle" >
  <solid android:color="#28bf3c" />
  <stroke android:width="1.5dp" android:color="#000000"/>
  <corners android:radius="25dp"/>


  <item android:state_pressed="true" >
    <shape>
      <solid android:color="#1b7196" />
    </shape>
  </item>

  <item android:state_focused="true" >
    <shape>
      <solid android:color="#1b7196" />
    </shape>
  </item>

  <item>
    <shape>
      <solid android:color="#28bf3c" />
    </shape>
  </item>
</shape>

但是如何将这两个文件合并为一个文件?

1 个答案:

答案 0 :(得分:0)

您可以在一个xml(根据您的需要的颜色)中这样做:

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false">
    <shape android:shape="rectangle">
      <corners android:radius="25dp" />
      <solid android:color="#24c139" />
      <stroke android:width="1.5dp" android:color="#000" />
    </shape>
  </item>
  <item android:state_pressed="true">
    <shape android:shape="rectangle">
      <corners android:radius="25dp" />
      <solid android:color="#318e3e" />
      <stroke android:width="1.5dp" android:color="#000" />
    </shape>
  </item>
</selector>