最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 軟鍵盤狀態(tài)并隱藏輸入法的實例

 更新時間:2017年09月04日 15:12:44   作者:lfdfhl  
這篇文章主要介紹了Android 軟鍵盤狀態(tài)并隱藏輸入法的實例的相關資料,這里提供實例實現(xiàn)軟鍵盤切換并隱藏輸入法的鍵盤,需要的朋友可以參考下

Android 軟鍵盤狀態(tài)并隱藏輸入法的實例

1 軟鍵盤狀態(tài)的切換 

2 強制隱藏輸入法鍵盤

MainActivity如下:

package cc.c; 
 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.app.Activity; 
import android.content.Context; 
/** 
 * Demo描述: 
 * 1 軟鍵盤狀態(tài)的切換 
 * 2 強制隱藏輸入法鍵盤 
 */ 
public class MainActivity extends Activity { 
  private EditText mEditText; 
  private Button mButton; 
  private Context mContext; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    init(); 
  } 
   
  private void init(){ 
    mContext=this; 
    mEditText=(EditText) findViewById(R.id.editText); 
    mButton=(Button) findViewById(R.id.button); 
    mButton.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
        //toggleInput(mContext); 
        hideInput(mContext,mEditText); 
      } 
    }); 
  } 
   
  /** 
   * 切換軟鍵盤的狀態(tài) 
   * 如當前為收起變?yōu)閺棾?若當前為彈出變?yōu)槭掌?
   */ 
  private void toggleInput(Context context){ 
    InputMethodManager inputMethodManager = 
    (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); 
  } 
   
  /** 
   * 強制隱藏輸入法鍵盤 
   */ 
  private void hideInput(Context context,View view){ 
    InputMethodManager inputMethodManager = 
    (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); 
  } 
 
 
} 

main.xml如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:paddingBottom="@dimen/activity_vertical_margin" 
  android:paddingLeft="@dimen/activity_horizontal_margin" 
  android:paddingRight="@dimen/activity_horizontal_margin" 
  android:paddingTop="@dimen/activity_vertical_margin" 
  tools:context=".MainActivity" > 
 
  <EditText 
    android:id="@+id/editText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:hint="Input here" /> 
 
  <Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/editText" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="15dp" 
    android:hint="Button" /> 
 
</RelativeLayout> 

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • Android自定義收音機搜臺控件RadioRulerView

    Android自定義收音機搜臺控件RadioRulerView

    這篇文章主要為大家詳細介紹了Android自定義收音機搜臺控件RadioRulerView的相關代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android自定義帶加載動畫效果的環(huán)狀進度條

    Android自定義帶加載動畫效果的環(huán)狀進度條

    這篇文章主要介紹了Android自定義帶加載動畫效果的環(huán)狀進度條,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android 讀取assets和raw文件內容實例代碼

    Android 讀取assets和raw文件內容實例代碼

    這篇文章主要介紹了Android 讀取assets和raw文件內容的相關資料,并附簡單實例代碼,需要的朋友可以參考下
    2016-10-10
  • Android Jetpack庫剖析之Lifecycle組件篇

    Android Jetpack庫剖析之Lifecycle組件篇

    本章也是帶來了Jetpack中我認為最重要的架構組件Lifecycle的原理探索,至于為什么覺得它是最重要是因為像ViewModel,LiveData這些組件也依賴于Lifecycle來感知宿主的生命周期,那么本章我們帶著幾個問題來探索一下這個組件
    2022-07-07
  • Android aapt自動打包工具詳細介紹

    Android aapt自動打包工具詳細介紹

    這篇文章主要介紹了Android aapt自動打包工具詳細介紹的相關資料,需要的朋友可以參考下
    2016-12-12
  • Android Socket服務端與客戶端用字符串的方式互相傳遞圖片的方法

    Android Socket服務端與客戶端用字符串的方式互相傳遞圖片的方法

    這篇文章主要介紹了Android Socket服務端與客戶端用字符串的方式互相傳遞圖片的方法的相關資料,需要的朋友可以參考下
    2016-05-05
  • Android應用動態(tài)修改主題的方法示例

    Android應用動態(tài)修改主題的方法示例

    今天小編就為大家分享一篇關于Android應用動態(tài)修改主題的方法示例,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Android中WebView用法實例分析

    Android中WebView用法實例分析

    這篇文章主要介紹了Android中WebView用法,以實例形式較為詳細的分析了Android中WebView的功能、注意事項與使用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-10-10
  • android長截屏原理及實現(xiàn)代碼

    android長截屏原理及實現(xiàn)代碼

    本篇文章主要介紹了android長截屏原理及實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Flutter里面錯誤捕獲的正確方法

    Flutter里面錯誤捕獲的正確方法

    這篇文章主要給大家介紹了關于Flutter里面錯誤捕獲的正確方法,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Flutter具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-10-10

最新評論

芦山县| 连州市| 沁水县| 宁南县| 济阳县| 永福县| 南召县| 高台县| 偏关县| 瓦房店市| 马鞍山市| 博白县| 五华县| 朝阳区| 老河口市| 长白| 盱眙县| 甘洛县| 蓝田县| 七台河市| 宁夏| 酉阳| 株洲县| 楚雄市| 阳江市| 睢宁县| 汉川市| 香港| 长顺县| 德州市| 河源市| 永年县| 准格尔旗| 甘泉县| 南汇区| 襄城县| 潞城市| 浦东新区| 达尔| 宜兴市| 平阳县|