久久久久久久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問題)
主站蜘蛛池模板: 久久影院一区 | 精品国产91 | 在线观看特色大片免费网站 | 日本精品视频 | 亚洲高清免费 | caoporon| 国产精品美女久久久久aⅴ国产馆 | 国产精品美女久久久久久免费 | 成年人黄色一级毛片 | 久久黄网 | 亚洲视频免费在线观看 | 欧美综合在线视频 | 午夜精品久久久久久久星辰影院 | 成人午夜电影网 | 天天人人精品 | 亚洲国产精品91 | 国产乱码精品一区二区三区忘忧草 | 91精品国产综合久久精品 | 日韩高清一区二区 | 国产精品成人一区二区三区夜夜夜 | 人妖av| 欧美黑人国产人伦爽爽爽 | 国产日韩精品一区 | 色视频免费 | 午夜资源 | 午夜精品久久 | 亚洲一区二区三区四区五区午夜 | 在线看黄免费 | 国产精品区一区二区三 | 色噜噜亚洲男人的天堂 | 九九精品在线 | 成人免费网站视频 | 国内精品视频一区二区三区 | 国产精品美女久久久久久久久久久 | av毛片| 日韩精品一区二区三区 | 一级片av | 91精品欧美久久久久久久 | 精品日韩一区二区 | 精品在线 | 99爱在线观看 |