Git Product home page Git Product logo

kulakeyboard's Introduction

KulaKeyboard

Android仿微信键盘输入法/表情/更多面板切换

效果展示

  • 微信
    微信效果展示
  • KulaKeyboard
    KulaKeyboard效果展示

使用方式

  1. 添加依赖
    在app build.gradle添加以下代码:

     implementation 'com.freddy:kulakeyboard_lib:1.0.1'   
    
  2. AndroidManifest.xml设置对应的activity节点android:windowSoftInputMode="adjustNothing"或在Activity setContentView()之前调用window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)

  3. 自定义输入法面板(参考CInputPanel)、表情面板(参考CExpressionPanel)、更多面板(参考CMorePanel)。

  4. 初始化KeyboardHelper并绑定对应自定义Panel及设置获取到的键盘高度等

private lateinit var keyboardHelper: KeyboardHelper
keyboardHelper = KeyboardHelper()
        keyboardHelper.init(this)
            .bindRootLayout(layout_main)
            .bindBodyLayout(layout_body)
            .bindInputPanel(chat_input_panel)
            .bindExpressionPanel(expression_panel)
            .bindMorePanel(more_panel)
            .setKeyboardHeight(
                if (App.instance.keyboardHeight == 0) DensityUtil.getScreenHeight(applicationContext) / 5 * 2 else App.instance.keyboardHeight
            )
            .setOnKeyboardStateListener(object : KeyboardHelper.OnKeyboardStateListener {
                override fun onOpened(keyboardHeight: Int) {
                    App.instance.keyboardHeight = keyboardHeight
                }

                override fun onClosed() {
                }
            })

注:如果应用有登录页面,可在用户登录弹出软键盘时获取键盘高度并保存到本地,方便下次使用。如果没有登录页面,则可以选择首次设置键盘高度为某个值,比如屏高度的2/5,这样在第一次弹出软键盘或面板时,或存在高度显示的瑕疵,在弹出键盘后,即获取到键盘高度,此时KulaKeyboard库会自动更新对应的值,后续会显示正确。目前Android系统并不提供直接获取键盘高度的方式,只能这样处理。考虑到一半社交App都需要登录,或在其它页面弹出软键盘时及时更新本地保存的键盘高度的值即可,影响不大。

以上步骤即可。

另外,贴上Activity布局文件,仅供参考

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:clipChildren="false"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/top_bar">

        <LinearLayout
            android:id="@+id/layout_body"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#333333" />

            <com.freddy.kulakeyboard.sample.CInputPanel
                android:id="@+id/chat_input_panel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <com.freddy.kulakeyboard.sample.CExpressionPanel
            android:id="@+id/expression_panel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="invisible" />

        <com.freddy.kulakeyboard.sample.CMorePanel
            android:id="@+id/more_panel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="invisible" />
    </LinearLayout>

    <TextView
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="#00bfcf"
        android:gravity="center"
        android:textStyle="bold"
        android:text="TopBar"
        android:textColor="#000000"
        android:textSize="18sp"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

使用过程中,如果有任何疑问,请联系我。

开源不易。如果该项目对你有帮助,麻烦点个star鼓励一下作者。另外,欢迎fork和pr,让我们共同完善。

QQ交流群:1015178804,目前是Android IM技术交流群,后续写的文章,也会用此群进行交流。

最新新开了一个微信公众号,方便后续KulaChat发布一些系列文章,同时也是为了激励自己写作。主要发布一些原创的Android IM相关的文章(也会包含其它方向),不定时更新。感兴趣的同学可以关注一下,谢谢。PS:感觉鸿洋大神提供的公众号文章排版方式,感激不尽~~

FreddyChen的微信公众号

License

Copyright 2020, chenshichao

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

kulakeyboard's People

Contributors

freddychen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kulakeyboard's Issues

onGlobalLayout 需要判定全屏以及导航栏开启状态,不然会产生误判

使用PopupWindow辅助监听来将主视图设为adjustNothing,确实是个好方法。
onGlobalLayout 的判断经过我使用多种真机测试,发现需要做很多无效性判定。不然很容易产生误判。

1.横屏模式在切入后台,再切回前台,部分手机会产生视图旋转。触发布局调整。
2.底部导航栏状态变更会触发布局调整。
3.有些时候我们并不会把app设置为全屏,计算键盘高度并不总等于物理高减可视底。
4.有些机型点开软键盘后会频繁触发onGlobalLayout。

这个是我自己使用的一个,可以参考一下。
https://bitbucket.org/mm_longcheng/mm-core/src/dev/nwsi/proj/android/src/org/mm/nwsi/mmUIViewLayoutListener.java

在全屏显示时获取软键盘高度不准确

您好,通过 鸿洋公众号慕名而来。使用后发现在全屏显示时获取的软键盘高度不准确,简单调试后发现pop设置的高度与屏幕实际高度总是存在一些偏差,怀疑是状态栏导致的,烦请博主有时间看下

键盘收起来的问题

image
在点击事件里没有添加收起键盘的操作,为什么每点一次,键盘就会被收起一次?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.