欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實(shí)現(xiàn)點(diǎn)擊EditText之外的控件隱藏軟鍵盤功能

 更新時(shí)間:2017年06月14日 09:28:38   作者:_iorilan  
這篇文章主要介紹了Android編程實(shí)現(xiàn)點(diǎn)擊EditText之外的控件隱藏軟鍵盤功能,涉及Android控件的功能、屬性及相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)點(diǎn)擊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);
      }
    }
}

點(diǎn)擊除EDITTEXT之外的控件隱藏軟鍵盤,如果是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相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android自定義軟鍵盤的設(shè)計(jì)與實(shí)現(xiàn)代碼

    Android自定義軟鍵盤的設(shè)計(jì)與實(shí)現(xiàn)代碼

    本篇文章主要介紹了 Android自定義軟鍵盤的設(shè)計(jì)與實(shí)現(xiàn)代碼,有需要的可以了解一下。
    2016-11-11
  • Android利用Sensor(傳感器)實(shí)現(xiàn)指南針小功能

    Android利用Sensor(傳感器)實(shí)現(xiàn)指南針小功能

    這篇文章主要為大家詳細(xì)介紹了Android利用Sensor(傳感器)實(shí)現(xiàn)指南針小功能的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 深入淺析Android消息機(jī)制

    深入淺析Android消息機(jī)制

    在Android中,線程內(nèi)部或者線程之間進(jìn)行信息交互時(shí)經(jīng)常會(huì)使用消息,這些基礎(chǔ)的東西如果我們熟悉其內(nèi)部的原理,將會(huì)使我們?nèi)菀住⒏玫丶軜?gòu)系統(tǒng),避免一些低級(jí)的錯(cuò)誤,通過本文給大家介紹android消息機(jī)制,感興趣的朋友一起學(xué)習(xí)吧
    2016-04-04
  • Android中ImageView使用網(wǎng)絡(luò)圖片資源的方法

    Android中ImageView使用網(wǎng)絡(luò)圖片資源的方法

    這篇文章主要介紹了Android中ImageView使用網(wǎng)絡(luò)圖片資源的方法,較為詳細(xì)的分析了ImageView調(diào)用網(wǎng)絡(luò)圖片的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android實(shí)現(xiàn)循環(huán)輪播跑馬燈的效果

    Android實(shí)現(xiàn)循環(huán)輪播跑馬燈的效果

    這篇文章主要介紹了為大家詳細(xì)介紹了如何通過Android實(shí)現(xiàn)循環(huán)輪播跑馬燈的效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-05-05
  • 淺談Android 指紋解鎖技術(shù)

    淺談Android 指紋解鎖技術(shù)

    這篇文章主要介紹了淺談Android 指紋解鎖技術(shù),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • flutter實(shí)現(xiàn)帶刪除動(dòng)畫的listview功能

    flutter實(shí)現(xiàn)帶刪除動(dòng)畫的listview功能

    最近接了一個(gè)新項(xiàng)目,需要開發(fā)帶有刪除動(dòng)畫效果的listview功能,在實(shí)現(xiàn)過程中列表滾動(dòng)效果用listview實(shí)現(xiàn)的,本文通過實(shí)例代碼給大家分享實(shí)現(xiàn)過程,感興趣的朋友跟隨小編一起學(xué)習(xí)下吧
    2021-05-05
  • Android 中 WebView 的基本用法詳解

    Android 中 WebView 的基本用法詳解

    這篇文章主要介紹了Android 中 WebView 的基本用法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)

    Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)學(xué)生管理系統(tǒng)的相關(guān)代碼,供大家學(xué)習(xí)借鑒,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android實(shí)現(xiàn)九宮格(GridView中各項(xiàng)平分空間)的方法

    Android實(shí)現(xiàn)九宮格(GridView中各項(xiàng)平分空間)的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)九宮格(GridView中各項(xiàng)平分空間)的方法,涉及Android針對(duì)GridView操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06

最新評(píng)論