安卓原生的EditText选择 [英] Android EditText native selector

查看:107
本文介绍了安卓原生的EditText选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运用我自己的设计来EDITTEXT,并使用Android原生选择的时候,我的EditText启用,重点等的问题是,每次我碰的EditText和本机选择正在我的EditText变小。 ?任何人都可以请说明为什么发生这种情况这是我的code片断:

I try to apply my own design to edittext and to use android native selector when my edittext is enabled, focused, etc. The problem is that every time I touch the edittext and the native selector is working my edittext becomes smaller. Can anyone please suggest why this is happening?Here is my code snippet:

<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>

在这里,我用我的选择:

And here I use my selector:

 <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>

这是my_border的code:

This is the code of 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>

P.S。绝对是同样的事情发生的按钮。

P.S. absolutely the same thing is happening with the buttons.

推荐答案

由于没有人能够完全回答我的问题,我会用自己的回答。问题是,我的EditText变小每次我摸了一下时间。这是因为本地的EditText背景,Android有它周围的透明区域。所以我用了一层列表还可以创建我的背景与它周围的透明区域。这里是code:

Since no one was able to completely answer my question I will answer it by myself. The problem was that my edittext became smaller every time I touched it. That happens because native edittext background in Android has a transparent area around it. So I used a layer list to create my background also with a transparent area around it. Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/transparent_background"
        android:top="5dip"
        android:right="5dip"
        android:bottom="5dip"
        android:left="5dip" />
    <item
        android:drawable="@drawable/my_border"
        android:top="0dip"
        android:right="0dip"
        android:bottom="0dip"
        android:left="0dip" />
</layer-list>

在我的选择,而不是 my_border 我用这个XML。 而已。易做,地狱很难找出如何!

In my selector instead of my_border I use this xml. That's it. Easy to do and hell difficult to find out how!

这篇关于安卓原生的EditText选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆