Android强制弹出,隐藏输入法.
当我们弹出一个Dialog时候,如果这个Dialog需要输入数据,然后确定后又需要关闭输入法,一般系统的hide,跟show方法总会有各种问题,最霸道的解决方法就是写一个定时器,定时弹出或者关闭输入法。
import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; public class InputTools { //隐藏虚拟键盘
public static void HideKeyboard(View v)
{
InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
if ( imm.isActive( ) ) {
imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) , 0 ); }
} //显示虚拟键盘
public static void ShowKeyboard(View v)
{
InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE ); imm.showSoftInput(v,InputMethodManager.SHOW_FORCED); } //强制显示或者关闭系统键盘
public static void KeyBoard(final EditText txtSearchKey,final String status)
{ Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run()
{
InputMethodManager m = (InputMethodManager)
txtSearchKey.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if(status.equals("open"))
{
m.showSoftInput(txtSearchKey,InputMethodManager.SHOW_FORCED);
}
else
{
m.hideSoftInputFromWindow(txtSearchKey.getWindowToken(), 0);
}
}
}, 300);
} //通过定时器强制隐藏虚拟键盘
public static void TimerHideKeyboard(final View v)
{
Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run()
{
InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
if ( imm.isActive( ) )
{
imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) , 0 );
}
}
}, 10);
}
//输入法是否显示着
public static boolean KeyBoard(EditText edittext)
{
boolean bool = false;
InputMethodManager imm = ( InputMethodManager ) edittext.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
if ( imm.isActive( ) )
{
bool = true;
}
return bool; }
}
Android强制弹出,隐藏输入法.的更多相关文章
- Android之弹出/隐藏系统软键盘
Android弹出/隐藏系统软键盘的代码如下: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT ...
- Android软键盘强制弹出,隐藏输入法.
本文实例讲述了Android实现弹出键盘代码,是一个非常实用的功能.代码非常简洁.分享给大家供大家参考. 具体功能代码如下: ? 1 2 3 4 5 6 7 8 Timer timer = new T ...
- android EditText设置弹出数字输入法键盘
<EditText android:id="@+id/edit_digit_input" android:layout_width="wrap_ ...
- android软键盘弹出隐藏的监听
通过网上搜索关于软键盘的隐藏弹出的监听,有几种方式,其中最有效的方式是在View的Onlayout()里面做文章 具体代码: 将布局视图自定义,重写onlayout()方法,然后在主Activity里 ...
- Android屏幕底部弹出DialogFragment(3)
Android屏幕底部弹出DialogFragment(3) 附录文章1,2的DialogFragment是常规的DialogFragment,但是现在的一些Android开发中,往往需要从底部 ...
- js 弹出 隐藏层和cookie
<script type="text/javascript"> function checkCookie(show_div, bg_div) { var smtstk ...
- Android实现弹出输入法时,顶部固定,中间部分上移的效果
前言 最近做项目时碰到一个问题,在意见反馈里面,提交按钮写到顶部,当用户输入反馈意见或者邮箱手机号时,弹出的输入法会上移整个页面,导致提交按钮显示不了. 很明显,这样的界面是非常不友好的,找了一些资料 ...
- Android 底部弹出Dialog(横向满屏)
项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog). 效果图如下所示(只显示关键部分): 步骤如下所示: 1.定义一个dialog的布局(lay ...
- Android popupwindow 弹出的位置问题
在Android开发中,需要用到PopupWindow这个类.在初始化完成,显示之前,都需要获得这个对象的width,height去计算popupWindow弹出的位置. 这个时候会发现取得的widt ...
随机推荐
- 关于UI资源获取资源的好的网站
前言:和我一样喜欢UI的一定喜欢这里的内容. 下面是关于sketch资源获取网页,点击图片就能进入: 连接是:https://github.com/JakeLin 居然意外百度到Sketch中国,还提 ...
- UVa 109 - SCUD Busters(凸包计算)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- Nuget~管理自己的包包~丢了的包包快速恢复
之前写过一篇Nuget~管理自己的包包的文章,今天来讲Nuget的另一个东西,就是找回丢失的DLL,我们在引用包包后,在当前解决方案根目录就生成一个packages的目前,里面有我们从nuget下载的 ...
- 手动将自定制的WebPart部署到 SharePoint 2010 中
1.搭建好开发环境,建立webpart工程,写代码. 2.修改assembly.cs文件 在部署前,需要修改assembly文件,增加以下两句: using System.Security; [a ...
- Java Concurrency In Practice - Chapter 1 Introduction
1.1. A (Very) Brief History of Concurrency motivating factors for multiple programs to execute simul ...
- 续Gulp使用入门-综合运用>使用Gulp构建一个项目
这是我的文件目录结构图 下面是我gulpfile.js的配置 'use strict' var gulp=require('gulp'); var gutil=require('gulp-util' ...
- linux进程间通信-XSI IPC
一 什么是XSI IPC 有三种 IPC我们称作XSI IPC,即消息队列.信号量以及共享存储器(共享内存),它们之间有很多相似之处. 二 标识符和键 每个内核中的 IPC结构(消息队 ...
- [瞎JB写] C++多态
似乎只能通过引用或者指针进行动态多态...蛋疼的语法 #include <iostream> #include <vector> #include <memory> ...
- linux command intro2 vi
vi cusor : 0 : to the beginning of the current line $ : to the end of the current line G : to the la ...
- Programming ActionScript 3.0 for Flash
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ec ...