• 调用和隐藏系统输入法


    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();

  • 相关阅读:
    HADOOP security
    apache sentry
    spark-deployment-modes-cluster-or-client
    Hadoop,Spark,Flink 相关KB
    OSGi类加载流程
    why-the-default-authentication-hadoop-is-unsecured ?
    Spring源码情操陶冶-PathMatchingResourcePatternResolver路径资源匹配溶解器
    maven跳过单元测试-maven.test.skip和skipTests的区别
    Maven+eclipse+jetty配置
    分布式事务资料
  • 原文地址:https://www.cnblogs.com/yiweiaimeng/p/5156809.html
Copyright © 2020-2023  润新知