更改Edittext onFouce(Android)的边框

更改Edittext onFouce(Android)的边框,android,android-edittext,Android,Android Edittext,我正在用android制作一个应用程序 一页中有3个编辑文本。我只想改变编辑文本的边框颜色,而我在上面写。简单地说。更改4的边框颜色 现在使用此代码作为背景和边框颜色 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ffffff" /> <stroke andr

我正在用android制作一个应用程序

一页中有3个编辑文本。我只想改变编辑文本的边框颜色,而我在上面写。简单地说。更改4的边框颜色

现在使用此代码作为背景和边框颜色

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#FF0000" />
</shape>


但是要更改焦点

在xml中创建另一个形状,并在键入时使用要更改的颜色。使用选择器,您可以更改焦点

试试看。我认为这很有帮助


此链接将帮助您使用Seletor。

在main_activity.xml中,在最外层的包装中(如果是线性布局),写下以下两行:

android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
然后在已经存在的文件中写入->

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true"

    >
    <shape >
        <solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#FF0000" />

    </shape>


</item>

<item android:state_window_focused="false">
    //the code for the edittext which will be by default

</item>

</selector>

//edittext的代码,默认情况下为

您能否提及在评论中给出的这两行添加位置?在布局文件夹的activity\u main.xml中的android:focusableInTouchMode=“true”android:DegenantFocusability=“BeforeDegenders”是。记得把它放在最外层的包装里。