Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在linearlayout中添加两个背景_Android - Fatal编程技术网

Android 如何在linearlayout中添加两个背景

Android 如何在linearlayout中添加两个背景,android,Android,这是我的代码,它将按钮大小更改为圆形,但不更改颜色。我该怎么办?在值文件夹的另一个文件colors.xml中定义颜色 我如何在一个代码改变按钮形状矩形也改变颜色时点击 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:s

这是我的代码,它将按钮大小更改为圆形,但不更改颜色。我该怎么办?在值文件夹的另一个文件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>

#ff0000
#0000ff
#00ff00

您可以使用框架布局。 在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>

您到底想实现什么目标?到目前为止,您的代码应该是这样工作的-您的形状始终是圆形的,但只有在按下时才会改变颜色检查链接