zoukankan      html  css  js  c++  java
  • 调用和隐藏系统输入法

    1.调用显示系统默认的输入法

    方法一、

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));

    方法二、

    InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)

    2.调用隐藏系统默认的输入法

    ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)

    3.获取输入法打开的状态

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    boolean isOpen=imm.isActive();
    isOpen若返回true,则表示输入法打开

    1、//隐藏软键盘   

    ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);   

    2、//显示软键盘,控件ID可以是EditText,TextView   

    ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0);  

    3、不自动弹出键盘:

    带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:

    方法一:在mainfest文件中把对应的activity设置

    android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。

    方法二:可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。

    注意TextView不要设置Visiable=gone,否则会失效
    ,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
    注意TextView不要设置Visiable=gone,否则会失效

    1 <TextView
    2         android:id="@+id/text_notuse"
    3         android:layout_width="wrap_content"
    4         android:layout_height="wrap_content"
    5         android:focusable="true"
    6 android:focusableInTouchMode="true"  />
    7 
    8 TextView textView = (TextView)findViewById(R.id.text_notuse);
    9 textView.requestFocus();

  • 相关阅读:
    node环境下安装vue-cli
    Git 查看、删除、重命名远程分支
    git 错误 fatal: Not a valid object name: 'master'.
    爬虫基本原理
    最长非重复子串(python实现)
    数据分析初步(jupyter常用快捷键,numpy,pandas,matplotlib常用用法)
    学linux,这篇就够了
    爬虫之requests
    nginx配置
    Linux下uwsgi服务器配置及重启
  • 原文地址:https://www.cnblogs.com/yiweiaimeng/p/5156809.html
Copyright © 2011-2022 走看看