我想知道如何在edittext获得焦点时更改它的边框颜色,目前它看起来像这样:
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:只要ET被聚焦,STATE_FOCUSED就会保持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);
这篇关于聚焦edittext时更改边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
EditText:禁用文本选择处理程序单击事件上的粘贴EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本选择处理程序单击事件上的粘贴/替换菜
2.3 上带有完成 SoftInput 操作标签的多行 EditTextMultiline EditText with Done SoftInput Action Label on 2.3(2.3 上带有完成 SoftInput 操作标签的多行 EditText)
如何在 Android 中检测向左或向右滑动?How to detect the swipe left or Right in Android?(如何在 Android 中检测向左或向右滑动?)
防止在Android中的屏幕旋转对话框解除Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋转对话框解除)
如何处理 ImeOptions 的完成按钮点击?How do I handle ImeOptions#39; done button click?(如何处理 ImeOptions 的完成按钮点击?)
您如何将 EditText 设置为仅接受 Android 中的数值How do you set EditText to only accept numeric values in Android?(您如何将 EditText 设置为仅接受 Android 中的数值?)