安卓悬浮编辑框实现

需求求 是在直播中实现聊天

问题 安卓默认的编辑框 在键盘弹出后 要么会布局整体顶上去 要么看不到输入内容

方案 使用 BasePopupWindow 实现悬浮编辑框

步骤 清单文件中配置该参数(防止出现系统将BasePopupWindow的编辑框顶上去的情况 BasePopupWindow已经处理了编辑框弹出的情况 如果交由系统处理会重复计算高度)


 <activity
            android:name="com.app.ui.LivePlayer"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"
//键盘弹出后不改变布局
            android:windowSoftInputMode="adjustNothing" />

设置点击虚拟编辑框后 弹出pw编辑框  直接将软键盘弹出 并设置背景透明位置信息一般是底部



                if (liveMsg == null) {

                    liveMsg = new BasePopupWindow(getActivity()) {
                        @Override
                        public View onCreateContentView() {
                        //xxx
                            return liveMsgBinding.getRoot();
                        }

                    };

                    liveMsg.setBackground(Color.TRANSPARENT);
                    liveMsg.setPopupGravity(Gravity.BOTTOM);
                }

                liveMsg.showPopupWindow();
                ViewUtils.openKeybord(liveMsgBinding.msg);

定义xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="375dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:gravity="bottom"
    tools:ignore="MissingDefaultResource">


    <EditText
        android:id="@+id/msg"
        style="@style/appText"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_margin="2dp"
        android:background="@drawable/live_edit"
        android:hint="在这里跟老师互动哦~"
        android:imeOptions="actionSend"
        android:inputType="text"
        android:paddingStart="15dp"
        android:singleLine="true"
        android:text="" />


</LinearLayout>

至此就可以实现安卓任意情况悬浮输入

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值