JKeyboardPanelSwitch 介绍
JKeyboardPanelSwitch是一款用于Android键盘面板冲突,布局闪动处理方案的软件。
效果对比
如何使用
在build.gradle中:
compile 'cn.dreamtobe.kpswitch:library:1.3.0'
对应的Activity,在Manifest中配置android:windowSoftInputMode=adjustResize:
<manifest ...> <application ...> <activity android:name=".activity.ChattingActivity" android:windowSoftInputMode=adjustResize"/> ... </application> ... </manifest>
在面板页面的layout中:
<?xml version="1.0" encoding="utf-8"?> <cn.dreamtobe.kpswitch.widget.CustomrootLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 布局内容 --> ... <cn.dreamtobe.kpswitch.widget.PanelLayout android:id="@+id/panel_root" android:layout_width="fill_parent" android:layout_height="@dimen/panel_height" android:visibility="gone"> <!-- 面板内容 --> ... </cn.dreamtobe.kpswitch.widget.PanelLayout> </cn.dreamtobe.kpswitch.widget.CustomrootLayout>
在Activity中:
... private PanelLayout mPanelLayout; // 任何的可以用于收键盘输入的View,可有可无,用于显示keyboard的时候传入 private EditText mSendEdt; @Override public void onCreate(Bundle saveInstanceState){ ... mPanelLayout = (PanelLayout)findViewById(R.id.panel_root) } ... // Keyboard与面板相互切换 public void switchPanel(){ if (mPanelLayout.getVisibility() == View.VISIBLE){ KeyboardUtil.showKeyboard(mSendEdt); } else { KeyboardUtil.hideKeyboard(mSendEdt); showPanel() } } public void hidePanel(){ mPanelLayout.setVisibility(View.GONE); } public void showPanel(){ mPanelLayout.setVisibility(View.VISIBLE); } ... // 如果需要处理返回收起面板的话 @Override public boolean dispatchKeyEvent(KeyEvent event){ if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (mPanelLayout.getVisibility() == View.VISIBLE) { hidePanel(); return true; } } return super.dispatchKeyEvent(event); }
JKeyboardPanelSwitch 官网
https://github.com/Jacksgong/JKeyboardPanelSwitch
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。