国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Android使用EditText小技巧匯總

瀏覽:7日期: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、讓軟鍵盤出現搜索按鈕

Android使用EditText小技巧匯總

Android使用EditText小技巧匯總

核心代碼塊1:

這倆個一定要設置,要不然軟鍵盤不會出現搜索

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

Activity或者Fragment 要實現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://隱藏項目中彈框hideSoftInputMethod();//項目中個性化操作getEditTextValue();pageno = 1;getMedicineListInfoForApp(name,firstWord,type,level,pageno);break; default:break;} }}3、多行EditText的時候會出現光標在中間的問題:

關鍵代碼

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默認是gravity是center.就是從中間對齊。我們把他改成left啊top啊就OK了。

4、修改EditText的光標顏色

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

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

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

5、通過監聽OnFocusChangeListener判斷EditText的焦點與否

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來對文本內容的呈現做說明

android:ellipsize='end'

Android使用EditText小技巧匯總

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

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

/** * 通過使用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; }

到這里就結束啦。

以上就是Android使用EditText小技巧匯總的詳細內容,更多關于Android使用EditText的資料請關注好吧啦網其它相關文章!

標簽: Android
相關文章:
主站蜘蛛池模板: 欧美一级视频在线观看欧美 | 国产亚洲精品一区久久 | 性欧美高清久久久久久久 | 99精品久久99久久久久久 | 色综合久久一本首久久 | 欧美日韩免费做爰视频 | 成人一区二区免费中文字幕 | 99国产在线视频 | 久久免费看 | 57pao强力打造手机版 | 99热久久国产综合精品久久国产 | 高清国产精品久久 | 正能量www正能量免费网站 | 国产成人mv在线观看入口视频 | 精品日韩欧美 | 日本韩国中文字幕 | 狠狠色狠狠色综合久久第一次 | 日本一区二区三区高清在线观看 | 欧美日本一区 | 国内精品影院久久久久 | 亚洲精品一区二区三区在 | 日韩欧美一区二区三区在线观看 | 91精品国产免费网站 | 加勒比色综合 | 97免费视频观看 | 国产亚洲美女精品久久 | 成人免费视频网址 | 伊人色综合久久天天人手人停 | 美女被拍拍拍拍拍拍拍拍 | av毛片在线看 | 色内内免费视频播放 | 亚洲福利视频精选在线视频 | 最新理论三级中文在线观看 | 亚洲视频男人的天堂 | 成年免费a级毛片 | 亚洲韩精品欧美一区二区三区 | 久久久免费的精品 | 久久国产视频网站 | 免费一级淫片aaa片毛片a级 | 精品一区二区三区高清免费不卡 | a毛片在线看片免费 |