安卓常用工具类-SoftKeyboardUtils【软件盘工具类】
来源:互联网 发布:js是什么防水材料 编辑:程序博客网 时间:2024/05/17 09:04
主要在不同环境下控制键盘的隐藏和显示
package com.example.burro.demo.appframework.util;import android.app.Activity;import android.content.Context;import android.os.IBinder;import android.view.View;import android.view.inputmethod.InputMethodManager;import java.util.List;/**软件盘工具类 * Created by burro on 2017/5/26. */public class SoftKeyboardUtils { /** * 隐藏软键盘(只适用于Activity,不适用于Fragment) */ public static void hideSoftKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } /** * 隐藏软键盘(可用于Activity,Fragment) * * viewList 中需要放的是当前界面所有触发软键盘弹出的控件。 * 比如一个登陆界面, 有一个账号输入框和一个密码输入框, * 需要隐藏键盘的时候, 就将两个输入框对象放在 viewList 中, * 作为参数传到 hideSoftKeyboard 方法中即可。 */ public static void hideSoftKeyboard(Context context, List<View> viewList) { if (viewList == null) return; InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); for (View v : viewList) { inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } //显示软键盘 public static boolean showSystemKeyBord(Context context, View v) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); return imm.showSoftInput(v, InputMethodManager.SHOW_FORCED); } /** * 如果键盘弹起则隐藏 * @param token */ public static void hideKeyboard(Context context, IBinder token) { if (token != null) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } } }}
阅读全文
0 0
- 安卓常用工具类-SoftKeyboardUtils【软件盘工具类】
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类-LogUtils【日志打印工具类】
- 安卓常用工具类-FileUtils【文件相关的工具类】
- 安卓常用工具类-SharePreferenceUtils【偏好存储工具类】
- 安卓常用工具类-StringUtils【String字符串工具类】
- 安卓常用工具类-ToastUtils【提示工具类】
- 安卓常用工具类-NotifyUtils【通知工具类】
- 安卓常用工具类-CrashHandler【错误日志获取保存工具】
- 安卓开发常用工具类utils
- 安卓常用工具类-ControlsUtils【设备、尺寸相关的工具类】
- 安卓开发常用工具类和第三方框架
- 【常用工具类】解析工具类
- 安卓工具类
- 两种方法创建素数表
- C语言中相对路径的使用
- hostapd移植笔记
- Java异常总结
- AVL树的实现(C++)
- 安卓常用工具类-SoftKeyboardUtils【软件盘工具类】
- [DL]机器学习算法之支持向量机(Support Vector Machine)
- 田忌赛马——贪心算法(附加别人写的动态规划)
- VMware Ubuntu 全屏
- 【C++】inet_ptoa&inet_atop inet_pton&inet_ntop
- 基于51单片机的无线通讯公交报站系统
- 第四天-运算符
- 安装 cobra
- java线程之间的通信(等待/通知机制)