zoukankan      html  css  js  c++  java
  • android软键盘弹出隐藏的监听

    通过网上搜索关于软键盘的隐藏弹出的监听,有几种方式,其中最有效的方式是在View的Onlayout()里面做文章

    具体代码:

    将布局视图自定义,重写onlayout()方法,然后在主Activity里面调用接口就可以了

    /**
     * 为了监听软键盘的弹出隐藏
     * 
     */
    public class ResizeLayout extends LinearLayout {
    	private InputListener mListener;
    	
    	public interface InputListener {
    		void OnInputListener(boolean isHideInput);
    	}
    	
    	public void setOnResizeListener(InputListener l) {
    		mListener = l;
    	}
    	
    	public ResizeLayout(Context context, AttributeSet attrs) {
    		super(context, attrs);
    	}
    	
    	private boolean mHasInit = false;
    	private boolean mHasKeyboard = false;
    	private int mHeight;
    	
    	@Override
    	protected void onLayout(boolean changed, int l, int t, int r, int b) {
    		// TODO Auto-generated method stub
    		super.onLayout(changed, l, t, r, b);
    		if (!mHasInit) {
    			mHasInit = true;
    			mHeight = b;
    			System.out.println("mHeight= " + b);
    		}
    		else {
    			mHeight = mHeight < b ? b : mHeight;
    		}
    		
    		if (mHasInit && mHeight > b) { // mHeight代表键盘的真实高度 ,b代表在窗口中的高度 mHeight>b
    			mHasKeyboard = true;
    			mListener.OnInputListener(false);
    		}
    		if (mHasInit && mHasKeyboard && mHeight == b) { // mHeight = b
    			mHasKeyboard = false;
    			mListener.OnInputListener(true);
    		}
    	}
    
  • 相关阅读:
    2021.11.22 图书管理系统
    2021.12.2 综合案例建模分析
    78 内核级命令实现示例
    74 键盘驱动程序的完善
    81 文件系统设计与实现(一)
    浮点数在内存中的表示
    75 Shell 任务的实现(上)
    79 硬盘驱动程序设计(上)
    浮点数在内存中的表示
    77 Shell 任务的实现(下)
  • 原文地址:https://www.cnblogs.com/crazywenza/p/3513327.html
Copyright © 2011-2022 走看看