編輯:關於Android編程
本文實例講述了Android編程實現點擊EditText之外的控件隱藏軟鍵盤功能。分享給大家供大家參考,具體如下:
工具類
...
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);
}
}
}
點擊除EDITTEXT之外的控件隱藏軟鍵盤,如果是viewgroup控件,遞歸執行
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);
}
}
}
...
}
調用時只需要傳遞最外層的layout即可。
UtilApp.setupUI((RelativeLayout) findViewById(R.id.login_parent), mContext);
更多關於Android相關內容感興趣的讀者可查看本站專題:《Android控件用法總結》、《Android開發入門與進階教程》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android數據庫操作技巧總結》及《Android資源操作技巧匯總》
希望本文所述對大家Android程序設計有所幫助。
Android教程之fragment通信
一、Activity與Fragment之間通信1、Activity向Fragment傳值在Activity中使用setArguments封裝所需傳遞的值,在Fragmen
Android開發常用功能
1.定時器的實現(1)采用Handler的postDelayed(Runnable, long)方法 Handler handler =&n
一加手機3怎麼截屏 一加手機3截圖方法匯總
一加手機3手機是發布不久的全新旗艦手機,一加手機3延續上一代高性價比特點,非常受歡迎。那麼一加手機3怎麼截屏呢?下文下載吧小編給大家介紹一下一加手機3截圖方
在 Android* 商務應用中實施地圖和地理圍欄特性
摘要 本案例研究討論了如何將地圖和地理定位特性構建到 Android* 商務應用中,包括在 Google Maps* 上覆蓋商店位置,以及在設備進入商店地理圍欄鄰近區