久久久久久久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,如果它們有錯誤的數(shù)據(jù),我會將 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);

它只會刪除所有內(nèi)容,這不是我想要的.

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

謝謝!

推薦答案

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

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

Drawable originalDrawable = myEditText.getBackground();

然后,如果用戶輸入了錯誤的數(shù)據(jù),你可以設置你的紅色邊框 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 資源)也可以在您自己的系統(tǒng)上找到,在 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模板網(wǎng)!

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

相關文檔推薦

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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 欧洲性生活视频 | av天天看| 国产伦一区二区三区视频 | 欧美成人精品在线 | 国产激情在线 | 日本欧美国产在线 | 天天草天天爱 | 可以免费观看的av片 | 神马影院一区二区三区 | 国产精品国产成人国产三级 | 9porny九色视频自拍 | 正在播放国产精品 | 亚洲视频免费在线播放 | 中文字幕二区 | 99精品国产一区二区青青牛奶 | 性色视频 | 中文字字幕在线中文乱码范文 | 黄色片免费看 | 中文字幕av在线播放 | 亚洲精品久久久久久久不卡四虎 | 午夜三区 | 欧美黄色片 | www.久久久| 日韩在线视频一区 | 成人久久久久 | 日韩一区二区福利 | 久久毛片 | 精品欧美黑人一区二区三区 | 秋霞在线一区 | 好姑娘影视在线观看高清 | www.日本国产 | av网站免费观看 | 一区二区播放 | 欧美日韩国产一区二区三区 | 日韩国产在线观看 | 国产高清精品一区二区三区 | 国产激情在线 | 亚洲欧美一区二区三区国产精品 | 99re6在线视频精品免费 | 亚洲成人av | 中文字幕视频网 |