当编辑文本聚焦时更改边框颜色 [英] Change border color when edittext is focused
问题描述
我想知道如何在聚焦时更改编辑文本的边框颜色,目前看起来像这样:
I am wondering how I can change the border color of the edittext when it is focused, at the moment it looks like this:
我已经尝试在SDK中检查源图片,但我无法理解它,我也尝试过使用xml,但无法仅更改边框颜色.
I have tried checking in the SDK for the source picture, but I couldn't make any sense of it, and I have also tried with xml, but was unable to change only the border color.
如果我找到了可以在 photoshop 中编辑以更改颜色的源图片,有关如何执行此操作或源图片位于何处的任何提示?:)
If I find the source picture I could edit in photoshop to change the color, any tips on how I could do this, or where the source picture is located? :)
推荐答案
您可以为 EditText 创建自定义形状
You can create a custom shape for your EditText
1:STATE_ENABLED是检查ET是否开启/关闭.
1: STATE_ENABLED is to check if the ET is enabled/disabled.
2: STATE_PRESSED 是检查 ET 何时被按下(它会改变印刷机上的颜色,但不会保持那样.)
2: STATE_PRESSED is to check when the ET is pressed (it will change the color on the press but won't keep it that way.)
3: STATE_FOCUSED 保持 ET 边框颜色改变,只要 ET 聚焦(这满足要求).
3: STATE_FOCUSED keeps the ET border color changed as long as the ET is focused(This fulfills the requirement).
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_focused="true">
<shape android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke android:width="2dp" android:color="#ffa0a496" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:padding="10dp"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
</selector>
并设置背景:
editText.setBackgroundResource(R.drawable.yourFile);
这篇关于当编辑文本聚焦时更改边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!