目前很多的輸入法都有自動(dòng)提示補(bǔ)全功能,在一些應(yīng)用場(chǎng)景里不適用,需要禁用系統(tǒng)輸入法,自定義軟鍵盤,EditText的光標(biāo)問(wèn)題是比較頭疼的,網(wǎng)上的說(shuō)法很多,然而大部分都是解決不了問(wèn)題的。以下是本人做的一個(gè)demo供網(wǎng)友參考。
長(zhǎng)寧網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,長(zhǎng)寧網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為長(zhǎng)寧上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的長(zhǎng)寧做網(wǎng)站的公司定做!
直接上代碼:
xml軟鍵盤:
<android.inputmethodservice.KeyboardView android:id="@+id/keyboard_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/white" android:focusable="true" android:focusableInTouchMode="true" android:keyBackground="@drawable/btn_keyboard_key" android:keyTextColor="@color/black" android:visibility="gone" />
禁用系統(tǒng)輸入法,解決EditText光標(biāo)問(wèn)題的重要代碼:
public boolean onTouch(View v, MotionEvent event)
{
//隱藏輸入法,顯示光標(biāo)
EditText et=(EditText)v;
int inType = et.getInputType(); // back up the input type
if (sdkInt>=11) {
Class<EditText> cls=EditText.class;
try {
Method setShowSoftInputOnFocus=cls.getMethod("setShowSoftInputOnFocus", boolean.class);
setShowSoftInputOnFocus.setAccessible(false);
setShowSoftInputOnFocus.invoke(et, false);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}else {
et.setInputType(android.text.InputType.TYPE_NULL); // disable soft input
et.setInputType(inType);
}
keyboardUtil=null;
keyboardUtil = new KeyboardUtil(act, ctx, et);
et.onTouchEvent(event);// call native handler
// restore input type
keyboardUtil.showKeyboard();
return true;
}
其他代碼就不貼了,需要完整demo的請(qǐng)自行下載。
當(dāng)前題目:android安卓屏蔽禁用系統(tǒng)輸入法,自定義軟鍵盤,解決EditText光標(biāo)問(wèn)題demo
網(wǎng)站網(wǎng)址:http://www.chinadenli.net/article42/pgcchc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、響應(yīng)式網(wǎng)站、企業(yè)網(wǎng)站制作、做網(wǎng)站、全網(wǎng)營(yíng)銷推廣、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)