這篇文章將為大家詳細(xì)講解有關(guān)Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)軟鍵盤(pán)隱藏功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

成都創(chuàng)新互聯(lián)專(zhuān)業(yè)為企業(yè)提供臨城網(wǎng)站建設(shè)、臨城做網(wǎng)站、臨城網(wǎng)站設(shè)計(jì)、臨城網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、臨城企業(yè)網(wǎng)站模板建站服務(wù),十多年臨城做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
具體方法如下:
...
public static void hideKeyboard(Context ctx) {
if (ctx != null) {
View view = ((Activity) ctx).getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) ctx
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}點(diǎn)擊除EDITTEXT之外的控件隱藏軟鍵盤(pán),如果是viewgroup控件,遞歸執(zhí)行
public static void setupUI(View view, final Context ctx) {
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideKeyboard(ctx);
return false;
}
});
}
//If a layout container, iterate over children and seed recursion.
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setupUI(innerView, ctx);
}
}
}
...
}調(diào)用時(shí)只需要傳遞最外層的layout即可。
UtilApp.setupUI((RelativeLayout) findViewById(R.id.login_parent), mContext);
關(guān)于Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)軟鍵盤(pán)隱藏功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
網(wǎng)頁(yè)標(biāo)題:Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)軟鍵盤(pán)隱藏功能
本文地址:http://www.chinadenli.net/article2/ipphic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、小程序開(kāi)發(fā)、品牌網(wǎng)站設(shè)計(jì)、定制網(wǎng)站、網(wǎng)站導(dǎo)航、微信小程序
聲明:本網(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)