将选择器和图层列表添加到edittext

时间:2013-10-06 02:48:18

标签: java android xml selector

我打算在我的edittext上添加一个阴影,我知道如何添加阴影,但我还要在其上添加一个选择器,如何同时添加选择器和阴影?

选择器:

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

<item android:state_pressed="true" android:state_focused="true">
    <shape>
        <solid
            android:color="#3f3f3f"/>
        <stroke
            android:width="2.3dp"
            android:color="#656565" />
          <corners
            android:radius="2dp" />    
    </shape>
</item>

<item android:state_pressed="true" android:state_focused="false">
    <shape>
        <solid
            android:color="#3f3f3f"/>
        <stroke
            android:width="2.3dp"
            android:color="#656565" />      
          <corners
            android:radius="2dp" />        
    </shape>
</item>

<item android:state_pressed="false" android:state_focused="true">
    <shape>
        <solid
            android:color="#3f3f3f"/>
        <stroke
            android:width="2.3dp"
            android:color="#656565" />  
          <corners
            android:radius="2dp" />                           
    </shape>
</item>

<item android:state_pressed="true" android:state_focused="true">
    <shape>
        <stroke
            android:width="2.3dp"
            android:color="#F6EBC9" />
         <corners
            android:radius="10dp" />
    </shape>
</item>

<item android:state_enabled="true">
    <shape>
        <solid
            android:color="#3f3f3f"/>
        <padding 
                android:left="4dp"
                android:top="4dp"
                android:right="4dp"
                android:bottom="4dp"
            />
    </shape>
</item>

</selector>

影:

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

<!-- most improtant is order of layers -->

<!-- Bottom right side 2dp Shadow -->
<item >
    <shape android:shape="rectangle">
        <solid android:color="#000000" />          
    </shape>
</item>

<!-- Bottom 2dp Shadow -->
<item>
    <shape android:shape="rectangle">
        <solid android:color="#000000" />  
    </shape>
</item>

<!-- White Top color -->
<item android:bottom="3px" android:right="3px">
    <shape android:shape="rectangle">
        <solid android:color="#FFFFFF" />          
    </shape>
</item>

的EditText:

 <EditText
    android:id="@+id/searchScreen2Edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/textinputborder"
    android:ems="10"
    android:hint="Search Bus Station..."
    android:imeOptions="actionDone"
    android:inputType="textVisiblePassword"
    android:padding="8dip"
    android:textSize="18sp"

    android:shadowColor="#000000"
    android:shadowDx="1.2"
    android:shadowDy="1.2"
    android:shadowRadius="1.5"
    >

我不知道如何实现这两个原因我可以同时添加两个背景..怎么办呢?

0 个答案:

没有答案