entends:http://stackoverflow.com/questions/36837066/how-to-validate-virtual-keyboard-visibility

监听键盘弹出和收起.

/*
Somewhere else in your code
*/ RelativeLayout mainLayout = findViewById(R.layout.main_layout); // You must use your root layout
InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE); /*
Instantiate and pass a callback
*/ SoftKeyboard softKeyboard;
softKeyboard = new SoftKeyboard(mainLayout, im);
softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged()
{
@Override
public void onSoftKeyboardHide()
{
// Code here
} @Override
public void onSoftKeyboardShow()
{
// Code here
}
}); /*
Open or close the soft keyboard programatically
*/ softKeyboard.openSoftKeyboard();
softKeyboard.closeSoftKeyboard(); /*
SoftKeyboard can catch keyboard events when an EditText gains focus and keyboard appears
*/ /* Prevent memory leaks:
*/ @Override
public void onDestroy()
{
super.onDestroy();
softKeyboard.unRegisterSoftKeyboardCallback();
}
final View parentView= findViewById(R.id.myrootview);
parentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = root.getRootView().getHeight() - root.getHeight(); Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); if(heightDiff <= contentViewTop){
//Soft KeyBoard Hidden---button visible }else{
//Soft KeyBoard Shown---button hide
} }
});

Android 监听键盘弹出和收起.的更多相关文章

  1. swift 监听键盘弹出的高度

    // 监听键盘通知 NotificationCenter.default.addObserver(self, selector: #selector(ComposeViewController.key ...

  2. ios监听键盘弹出 频幕位置改变

  3. Android 监听键盘的弹起与收缩

    Android 监听键盘的弹起与收缩 由于android不存在该监听的API 所以需要自己去处理 先上代码 /* android:windowSoftInputMode="stateAlwa ...

  4. js 监听手机端键盘弹出和收起事件

    //这里区分不同系统,可以参考之前的文档记录 https://www.cnblogs.com/wind-wang/p/10737110.html const ua = typeof window == ...

  5. android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果

    需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果,  总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...

  6. android标题栏下面弹出提示框(一) TextView实现,带动画效果

    产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...

  7. Android EditText 不弹出输入法

    当第一次进入一个activity的时候  一般是第一个edittext是默认选中的,但是该死的软键盘也一起弹出来了 那是相当的不美观哈!(#‵′)凸.为此, 本大人就去寻找在刚进入这个activity ...

  8. PC电脑运行Android模拟器总是弹出“视频源”窗体的原因和解决方案

    原因: PC电脑运行Android模拟器时弹出“视频源”窗体,会让你"选择视频设备",如:HP TruevIsion HD,而这个视频设备就是你电脑中的内置摄像头,这个内置摄像头在 ...

  9. Android EditText不弹出输入法焦点问题的总结

    转自:http://mobile.51cto.com/aprogram-403138.htm 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

随机推荐

  1. 机器学习数据集,主数据集不能通过,人脸数据集介绍,从r包中获取数据集,中国河流数据集

    机器学习数据集,主数据集不能通过,人脸数据集介绍,从r包中获取数据集,中国河流数据集   选自Microsoft www.tz365.Cn 作者:Lee Scott 机器之心编译 参与:李亚洲.吴攀. ...

  2. [leetcode]Rotate List @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...

  3. Java 终于有 Lambda 表达式啦~Java 8 语言变化——Lambda 表达式和接口类更改【转载】

    原文地址 en cn 下载 Demo Java™ 8 包含一些重要的新的语言功能,为您提供了构建程序的更简单方式.Lambda 表达式 为内联代码块定义一种新语法,其灵活性与匿名内部类一样,但样板文件 ...

  4. CentOS 安装 Hadoop 手记

    Download & Install   download hadoop from http://hadoop.apache.org/releases.html#Download downlo ...

  5. [Python设计模式] 第7章 找人帮忙追美眉——代理模式

    github地址:https://github.com/cheesezh/python_design_patterns 题目1 Boy追求Girl,给Girl送鲜花,送巧克力,送洋娃娃. class ...

  6. C# System.Collections.Queue

    using System; using System.Collections; public class SamplesQueue { public static void Main() { // C ...

  7. C# System.Collections.Stack

    using System; using System.Collections; public class SamplesStack { public static void Main() { // C ...

  8. 使用yocs_cmd_vel_mux进行机器人速度控制切换

    cmd_vel_mux包从名字就可以推测出它的用途,即进行速度的选择(In electronics, a multiplexer or mux is a device that selects one ...

  9. pandas基础用法——索引

    # -*- coding: utf-8 -*- # Time : 2016/11/28 15:14 # Author : XiaoDeng # version : python3.5 # Softwa ...

  10. EntityFramework中常用的数据删除方式

    最近在学EF,目前了解到删除操作有三种方式, 第一,官方推荐的先查询数据,再根据查询的对象,删除对象. 这是第一种,官方推荐 第二,自己创建一个对象,然后附加,然后删除. 这是第二种 第三,自己创建对 ...