av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Android使用EditText小技巧匯總

瀏覽:17日期:2022-09-19 08:19:47
1、隱藏android中EditText自帶的的下劃線

android:background='@null'或android:background='@/drawable/bg_edittext_norma.xml'

bg_edittext_norma.xml

<?xml version='1.0' encoding='UTF-8'?><shape xmlns:android='http://schemas.android.com/apk/res/android'> <!--商品描述的可編輯框--> <solid android:color='#FFFFFF' /> <corners android:radius='10dip'/> <strokeandroid: android:color='#BDC7D8' /></shape>

<EditText android:layout_width='wrap_content' android:layout_height='wrap_content' android:background='@null' android:hint='輸入用戶名' android:paddingBottom='5dip' android:paddingTop='5dip' />2、讓軟鍵盤出現(xiàn)搜索按鈕

Android使用EditText小技巧匯總

Android使用EditText小技巧匯總

核心代碼塊1:

這倆個(gè)一定要設(shè)置,要不然軟鍵盤不會(huì)出現(xiàn)搜索

android:imeOptions='actionSearch'android:singleLine='true' 核心代碼塊2:

Activity或者Fragment 要實(shí)現(xiàn)TextView.OnEditorActionListener接口

public class DrugCatalogueInquiryFragment extends GeneralSocialFragment implements TextView.OnEditorActionListener { private ClearEditText etDrugName; etDrugName = xFindViewById(R.id.et_drug_name); etDrugName.setOnEditorActionListener(this); @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {doWhichOperation(actionId);return true; } private void doWhichOperation(int actionId) {switch (actionId) { case EditorInfo.IME_ACTION_SEARCH://隱藏項(xiàng)目中彈框hideSoftInputMethod();//項(xiàng)目中個(gè)性化操作getEditTextValue();pageno = 1;getMedicineListInfoForApp(name,firstWord,type,level,pageno);break; default:break;} }}3、多行EditText的時(shí)候會(huì)出現(xiàn)光標(biāo)在中間的問題:

關(guān)鍵代碼

android:gravity='left'

<EditText android:layout_width='match_parent' android:layout_height='wrap_content' android:minLines='5' android:background='#ffffff' android:paddingLeft='5dp' android:gravity='left' />

像這種。這是什么原因造成的呢?用來EdittText默認(rèn)是gravity是center.就是從中間對(duì)齊。我們把他改成left啊top啊就OK了。

4、修改EditText的光標(biāo)顏色

在使用EditText的XML 文件中加入一個(gè)屬性:

android:textCursorDrawable='@null'//或者android:textCursorDrawable = '#fff000'

這個(gè)屬性是用來控制光標(biāo)顏色的,'@null' 是作用是讓光標(biāo)顏色和text color一樣,當(dāng)然也可以修改成你自己的顏色。

5、通過監(jiān)聽OnFocusChangeListener判斷EditText的焦點(diǎn)與否

private void initListener(){etDrugName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) {if (b){ TypeUtils.getInstance( getActivity() ).hideKeyboardView();} }});etDrugNameOfInitial.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) {if (b){ TypeUtils.getInstance( getActivity() ).hideKeyboardView();} }}); }6、通過屬性android:ellipsize來對(duì)文本內(nèi)容的呈現(xiàn)做說明

android:ellipsize='end'

Android使用EditText小技巧匯總

7、通過屬性android:digits來規(guī)定只能輸入的值

android:digits='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'8、規(guī)定只能輸入中文

/** * 通過使用Android源碼中的InputFilter接口 */ InputFilter filter = new InputFilter() {public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) {if (!isChinese(source.charAt(i))) { return '';} } return null;} }; /** * 判定輸入漢字 * * @param c * @return */ public static boolean isChinese(char c) {Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { return true;}return false; }

到這里就結(jié)束啦。

以上就是Android使用EditText小技巧匯總的詳細(xì)內(nèi)容,更多關(guān)于Android使用EditText的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 国产精品久久久久久久久久久久 | 羞羞涩涩在线观看 | 亚洲一区综合 | 国产欧美日韩一区 | 中国一级毛片免费 | 免费观看成人性生生活片 | 国产激情网 | 拍拍无遮挡人做人爱视频免费观看 | 午夜一级做a爰片久久毛片 精品综合 | 久久亚洲精品国产精品紫薇 | 色婷婷激情综合 | 久久亚洲精品国产精品紫薇 | 在线黄av | 久久人人爽人人爽 | 热久色| 精品一二区 | 中文字幕一区二区三区乱码在线 | 一级在线观看 | 99tv| 中文字幕在线观看视频网站 | 中文字幕在线观看一区二区 | 日韩中文字幕一区二区 | 在线一区| 国产精品一区二区三区四区 | 国产高清在线精品 | 国产精品一区二区三区四区 | 中文字幕一区二区三区四区 | 欧美男人亚洲天堂 | 亚洲+变态+欧美+另类+精品 | 欧州一区| 亚洲精品乱码8久久久久久日本 | 国产高清精品一区二区三区 | 国产精品夜夜夜一区二区三区尤 | 天天综合日日夜夜 | 久久精品99国产精品日本 | 正在播放国产精品 | 亚洲三级国产 | 国产精品久久国产精品久久 | 91精品国产综合久久久密闭 | 亚洲日本乱码在线观看 | 国产精品夜夜春夜夜爽久久电影 |