久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果我應用背景,如何在 EditText 上返回默認樣式

How to return to default style on EditText if I apply a background?(如果我應用背景,如何在 EditText 上返回默認樣式?)
本文介紹了如果我應用背景,如何在 EditText 上返回默認樣式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我剛剛遇到了一個我不知道如何解決的問題.它看起來很傻,但我找不到解決方法.

I just encountered with a problem that I don't know how to solve. It looks silly but I cannot find a way to fix it.

我在 android 中有一個帶有多個 EditText 的表單,當您提交表單時,它會檢查那些 EditText,如果它們有錯誤的數據,我會將 EditText 更改為紅色邊框(應用 Ninepatch 圖像).

I have a form in android with several EditText and when you submit the form it checks those EditText and if they have wrong data I change the EditText to red border (applying a ninepatch image).

myEditText.setBackgroundResource(R.drawable.edittext_red);

問題是,當用戶更改EditText時,我想恢復android的默認樣式,但我不知道該怎么做.如果我這樣做:

The problem is, I want to restore android's default style when the user change the EditText, but I don't know how to do it. if I do:

myEditText.setBackgroundResource(0);

它只會刪除所有內容,這不是我想要的.

It will just remove everything and that's not what I want.

謝謝!

推薦答案

首先,在使用自己的 Ninepatch 調用 setBackgroundResource 之前,先存儲 EditText 的原始背景,如下所示:

First, before you call setBackgroundResource with your own ninepatch, store the original background of the EditText, like this:

Drawable originalDrawable = myEditText.getBackground();

然后,如果用戶輸入了錯誤的數據,你可以設置你的紅色邊框 Ninepatch:

Then, if the user entered the wrong data, you can set your red border ninepatch:

myEditText.setBackgroundResource(R.drawable.edittext_red);

然后,當你想恢復 EditText 的外觀時,使用存儲的 drawable:

And later, when you want to restore the look of the EditText, use the stored drawable:

myEditText.setBackgroundDrawable(originalDrawable);

或者您可以像這樣直接引用默認的 Android EditText 背景:

Alternatively you can reference the default Android EditText background directly like this:

myEditText.setBackgroundResource(android.R.drawable.edit_text);

在 androiddrawables,您可以看到不同的可繪制對象如何查找不同的 Android 版本,并獲取它們的資源標識符.此方法適用于所有可繪制對象,而不僅僅是 EditText

At androiddrawables you can see how the different drawables look for the different versions of Android, and get their resource identifier. This method should work for all drawables, not just EditText

這些(和其他 android 資源)也可以在您自己的系統上找到,在 android-sdk 文件夾中

These (and other android resources) can also be found on your own system, in the android-sdk folder in

/android-sdk/platforms/android-<API級別>/data/res/

< path to android-sdk folder>/android-sdk/platforms/android-< API level>/data/res/

這篇關于如果我應用背景,如何在 EditText 上返回默認樣式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 国产午夜在线观看 | 日韩在线免费观看视频 | 狠狠干综合 | 免费成人毛片 | 在线观看免费黄色 | 激情五月综合 | 欧洲美一区二区三区亚洲 | 欧美三级在线视频 | 亚洲国产精品va在线看黑人 | 91最新网站| 天堂中文av | 秋霞福利视频 | 日本久久精品 | 一级免费黄色片 | 亚洲综合免费 | 国产成人免费在线观看 | 91免费在线看 | 日本伊人网 | 日韩免费大片 | 欧美精品乱码99久久蜜桃 | 在线中文字幕 | 欧美视频在线观看免费 | 国产综合第一页 | 97香蕉视频 | 欧美另类z0zx974 | 日韩精品一区二区三区免费视频 | 欧美xx孕妇 | 午夜免费小视频 | 三级福利视频 | 国产成人精品一区二区三区四区 | 日日干日日操 | 日韩午夜在线观看 | 久久久国产精品视频 | 最新国产精品 | 99色在线 | 国产性色av | 中文字字幕 | 日韩在线精品 | 黄色片久久 | 午夜性影院| 中文在线视频 |