概述
需求求 是在直播中实现聊天
问题 安卓默认的编辑框 在键盘弹出后 要么会布局整体顶上去 要么看不到输入内容
方案 使用 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>
至此就可以实现安卓任意情况悬浮输入
最后
以上就是风趣裙子为你收集整理的安卓悬浮编辑框实现的全部内容,希望文章能够帮你解决安卓悬浮编辑框实现所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复