Android EditText原生选择器

sup*_*erM 2 android selector android-edittext

我尝试将自己的设计应用于edittext并在我的edittext启用,聚焦等时使用android原生选择器.问题是每次我触摸edittext并且本机选择器正在工作时我的edittext变得更小.任何人都可以建议为什么会发生这种情况?这是我的代码片段:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_window_focused="false" android:state_enabled="true"
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:state_window_focused="false" android:state_enabled="false"
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:state_pressed="true" 
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:state_enabled="true" android:state_focused="true" 
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:state_enabled="true" 
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:state_focused="true" 
    android:drawable="@android:drawable/edit_text"/>
<item 
    android:drawable="@drawable/my_border" />
</selector>
Run Code Online (Sandbox Code Playgroud)

在这里我使用我的选择器:

 <EditText 
        android:layout_height="37dip" 
        android:layout_width="fill_parent"
        android:layout_marginLeft="7dip"
        android:layout_marginRight="7dip"
        android:background="@layout/selector_input"
        android:paddingLeft="5dip"
        android:paddingRight="5dip"
        android:inputType="textEmailAddress">
    </EditText>
Run Code Online (Sandbox Code Playgroud)

这是my_border的代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white"/>
    <stroke android:width="1dip" android:color="@color/border_green"/>
    <corners android:radius="4dp" /> 
    <padding android:left="1dip" android:top="1dip" android:right="1dip" android:bottom="1dip" />
</shape>
Run Code Online (Sandbox Code Playgroud)

PS绝对与按钮一样发生.

cV2*_*cV2 8

首先,非常感谢您的帖子,帮助了我很多,但上面的代码(选择器的示例)并不适合我:

所以我适应了其他人,所以如果有人搜索如何将文本字段标记为选中:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/bottom_line_normal"/>
<item 
android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/bottom_line_normal"/>
<item 
android:state_pressed="true" 
android:drawable="@drawable/bottom_line_focus"/>
<item 
android:state_enabled="true" android:state_focused="true" 
android:drawable="@drawable/bottom_line_focus"/>
<item 
android:state_enabled="true" 
android:drawable="@drawable/bottom_line_normal"/>
<item 
android:state_focused="true" 
android:drawable="@drawable/bottom_line_focus"/>
<item 
android:drawable="@drawable/bottom_line_normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

玩得开心:=)祝你好运:)

  • 很高兴我帮助过你.谢谢你回答))) (2认同)