• Stars
    star
    252
  • Rank 160,734 (Top 4 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

More Repositories

1

NettyChat

基于Netty+TCP+Protobuf实现的Android IM库,包含Protobuf序列化、TCP拆包与粘包、长连接握手认证、心跳机制、断线重连机制、消息重发机制、读写超时机制、离线消息、线程池等功能。
Java
2,259
star
2

Silhouette

封装的Android常用控件,比如:SleTextButton、SleImageButton、SleConstraintLayout、SleFrameLayout、SleLinearLayout、SleRelativeLayout等。使控件具备Shape、Selector等功能,省去编写shape或selector文件的繁琐步骤。另外支持N种颜色渐变,弥补原生shape文件只支持三种颜色(startColor/centerColor/endColor)的不足等。
Kotlin
131
star
3

CEventCenter

一个Android事件分发中心库,基于对象池及接口回调实现。实现类似BroadcastReceiver/RxBus/EventBus等的消息事件传递功能,用于在Activity/Fragment/Service之间的消息传递通讯。
Java
117
star
4

Shine-Kotlin

基于Retrofit+Kotlin协程实现的Kotlin网络请求库封装,支持GET/POST/PUT/DELETE请求、动态BaseUrl、请求头、请求/响应日志等。同时,支持自定义Parser(数据解析器),用于解决不同返回数据Model。
Kotlin
86
star
5

KulaChat

基于ims_kula实现的Android即时通讯app
Java
56
star
6

Shine-Java

基于Retrofit+RxJava实现的Java网络请求库封装,支持GET/POST/PUT/DELETE请求、动态BaseUrl、请求头、请求/响应日志、自定义加解密器等。同时,支持自定义Parser(数据解析器),用于解决不同返回数据Model。
Java
46
star
7

ims_kula

Android IM SDK,包含TCP/WebSocket实现
Java
33
star
8

kulachat-server

KulaChat服务端,基于SpringBoot+Gradle构建。
Java
28
star
9

CWidget

一些Android通用的常用控件,比如可支持自定义属性shape/selector/corners radius的CTextButton
3
star
10

freddychen.github.io

个人博客
HTML
2
star
11

KulaMediaSelector

自定义媒体选择器
1
star
12

MarkdownImages

Markdown图床
Java
1
star