問題描述
我想知道如何在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模板網!