Android键盘处理

1.

//        topBarView.getViewTreeObserver().addOnGlobalLayoutListener(this);


2.

//        topBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

3.

    //注册监听视图树的观察者
//    @Override
//    public void onGlobalLayout() {
//        final LinearLayout llIcon = this.mLlIcon;
//        Rect KeypadRect = new Rect();
//
//        topBarView.getWindowVisibleDisplayFrame(KeypadRect);
//
//        int screenHeight = topBarView.getRootView().getHeight();
//
//        int keypadHeight = screenHeight - KeypadRect.bottom;
//
//        //更新键盘激活状态
//        if (keypadHeight > 0) {
//            updateKeyBoardActiveStatus(true);
//        } else {
//            updateKeyBoardActiveStatus(false);
//        }
//
//        if (keypadHeight > 0 && llIcon.getTag() == null) {
//            final int height = llIcon.getHeight();
//            final int width = llIcon.getWidth();
//            this.mLogoHeight = height;
//            this.mLogoWidth = width;
//            llIcon.setTag(true);
//            LoginBusiness.setTopMarginAnimator(llIcon, height, 0, 1);
//
//            LoginBusiness.setAlphaAnimator(llIcon, 1, 0);
//        } else if (keypadHeight == 0 && llIcon.getTag() != null) {
//            final int height = mLogoHeight;
//            llIcon.setTag(null);
//            LoginBusiness.setTopMarginAnimator(llIcon, height, 1, 0);
//            LoginBusiness.setAlphaAnimator(llIcon, 0, 1);
//        }
//    }

4.AndroidManifest.xml

android:windowSoftInputMode="adjustResize|stateHidden"

5.EditText

android:focusable="true"
android:focusableInTouchMode="true"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 系统的键盘事件 是由InputManagerService 来监控的, 而InputManagerService 是由 SystemServer 来启动的 创建了一个类的对象 WindowInputEvent Receiver InputEventRe ceiver的构造 函数 WindowInputEventReceiver extends InputEventReceiver nativeInit InputEventReceiver.cpp nativeInit android_view_InputE ventReceiver.cpp NativeInputE ventReceiver 的构造函数 LooperCallback: :handleEvent NativeInputEve ntReceiver::ha ndleEvent Looper::p ollInner Looper::p ollOnce NativeInputEventRecei ver : public LooperCallback 有方法 NativeInputEventReceiver:: handleEvent 没有键盘事件发生, InputManager 中的InputReader 正在睡眠等待键盘事件 的发生,而InputManager 中的 InputDispatcher 正在等待InputReader 从睡眠中醒过来并且唤醒它,而应用程 序也正在消息循环中等待InputDispatcher 从睡眠中醒过来并且唤醒它。 分析InputManager 分发键盘消息给应用程序的过程 InputReader .pollOnce EventHub.g etEvent InputReader::pr ocessEventsLock ed InputReader::pr ocessEventsForD eviceLocked InputDevic e::process 没有键盘事件发生, InputReaderThread 线程就会睡眠在EventHub.getEvent 函数 上,当键盘事件发生后,就会把这个事件封 装成一个RawEvent 对象,然后返回到 pollOnce函数中,执行此函数 有键盘事件 InputReader.cpp InputMapper::process( 这里 是KeyboardInputMapper) InputReader::createDeviceLock ed中根据类型创建的,负责处理轨迹 球事件的TrackballInputMapper 对 象以及负责处理触摸屏事件的 TouchInputMapper 对象等 KeyboardInputMap per::processKey 这个函数首先对对按 键作一些处理,例如 需要根据当时屏幕的 方向来调整键盘码 InputDispatcher::notify Key( 继承自 InputListenerInterface) KeyboardInputMappge r函数通知 InputDispatcher ,有 键盘事件发生了 1. 调用 validateKeyEvent 函数来验 证action参数是否正确 2. 参数action检查通过后,还通过 policyFlags 参数来检查一下同时是 否有ALT和SHIFT键被按下 3. 调用 enqueueInboundEventLocked 函数 把这个按键事件封装成一

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值