0

这是我的代码,将按钮大小更改为四舍五入但不更改颜色我该怎么办?在值文件夹中的另一个文件colors.xml中定义颜色我如何在一个代码中将按钮形状更改为矩形也单击时更改颜色???

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

 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
   <shape 
   android:shape="rectangle" android:padding="10dp">
 <!-- you can use any color you want I used here gray color-->
 <solid android:color="#E0E0E0"/> 
 <corners
 android:bottomRightRadius="10dp"
 android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
  android:topRightRadius="10dp"/>
 </shape>
 </item>
 <item android:state_focused="true" android:state_pressed="true" 
        android:drawable="@drawable/blue_color" /> 
  <item android:state_focused="false" android:state_pressed="true" 
        android:drawable="@drawable/red_color" /> 
  <item android:drawable="@drawable/green_color" />

 </selector>





  <!-- colors.xml --->
  <?xml version="1.0" encoding="utf-8"?>
 <resources>
<drawable name="red_color">#ff0000</drawable>
 <drawable name="blue_color">#0000ff</drawable>
<drawable name="green_color">#00ff00</drawable>
 </resources>
4

1 回答 1

0

您可以使用FrameLayout。在 FrameLayout 中设置背景,在 LinearLayout 中设置前背景。注意放置在 FrameLayout 背景之上的 LinearLayout 背景。

试试这个代码!

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bgBehind">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bgFront">

    </LinearLayout>
</FrameLayout>
于 2018-06-01T22:23:54.460 回答