Skip to content

Commit 873a64a

Browse files
committed
测试Bottom弹窗在弹出输入法时点击外部无法消失的Bug
1 parent 2bb3bb5 commit 873a64a

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

app/src/main/java/com/lxj/xpopupdemo/fragment/CustomPopupDemo.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
import android.content.Context;
44
import android.support.annotation.NonNull;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
57
import android.util.Log;
68
import android.view.View;
79
import android.widget.AdapterView;
810
import android.widget.ArrayAdapter;
911
import android.widget.Spinner;
1012
import android.widget.TextView;
1113

14+
import com.lxj.easyadapter.CommonAdapter;
15+
import com.lxj.easyadapter.ViewHolder;
1216
import com.lxj.xpopup.XPopup;
1317
import com.lxj.xpopup.animator.PopupAnimator;
18+
import com.lxj.xpopup.core.BottomPopupView;
1419
import com.lxj.xpopup.core.CenterPopupView;
1520
import com.lxj.xpopup.enums.PopupAnimation;
1621
import com.lxj.xpopup.util.XPopupUtils;
1722
import com.lxj.xpopupdemo.R;
1823

24+
import java.util.ArrayList;
25+
1926
/**
2027
* Description:
2128
* Create by dance, at 2018/12/9
@@ -44,8 +51,8 @@ public void onItemSelected(AdapterView<?> parent, View view, final int position,
4451
@Override
4552
public void run() {
4653
XPopup.get(getContext())
47-
.popupAnimation(datas[position])
48-
.asCustom(new CustomPopup(getContext()))
54+
// .popupAnimation(datas[position])
55+
.asCustom(new CustomPopup2(getContext()))
4956
// .setWidthAndHeight(XPopupUtils.getWindowWidth(getContext()),XPopupUtils.getWindowHeight(getContext()))
5057
.show();
5158
}
@@ -88,6 +95,46 @@ public void onClick(View v) {
8895
// @Override
8996
// protected int getMaxWidth() {
9097
// return 1200;
98+
// }
99+
}
100+
101+
static class CustomPopup2 extends BottomPopupView {
102+
RecyclerView recyclerView;
103+
public CustomPopup2(@NonNull Context context) {
104+
super(context);
105+
}
106+
107+
@Override
108+
protected int getImplLayoutId() {
109+
return R.layout.custom_popup2;
110+
}
111+
@Override
112+
protected void initPopupContent() {
113+
super.initPopupContent();
114+
recyclerView = findViewById(R.id.recyclerView);
115+
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
116+
ArrayList<String> data = new ArrayList<>();
117+
for (int i = 0; i < 3; i++) {
118+
data.add(""+i);
119+
}
120+
121+
recyclerView.setAdapter(new CommonAdapter<String>(android.R.layout.simple_list_item_1, data) {
122+
@Override
123+
protected void convert(@NonNull ViewHolder holder, @NonNull String s, int position) {
124+
holder.setText(android.R.id.text1, s);
125+
}
126+
});
127+
}
128+
129+
// @Override
130+
// protected int getMaxHeight() {
131+
// return 1200;
132+
// }
133+
//
134+
//返回0表示让宽度撑满window,或者你可以返回一个任意宽度
135+
// @Override
136+
// protected int getMaxWidth() {
137+
// return 1200;
91138
// }
92139
}
93140
}

app/src/main/res/layout/custom_popup.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
4+
android:layout_height="wrap_content"
55
android:background="#eee"
66
android:orientation="vertical"
77
android:padding="20dp">
@@ -61,7 +61,7 @@
6161
<EditText
6262
android:layout_width="match_parent"
6363
android:layout_height="wrap_content"
64-
android:layout_marginTop="325dp"
64+
android:layout_marginTop="35dp"
6565
android:layout_marginBottom="15dp"
6666
android:text="测试输入框会不会被软键盘盖住" />
6767

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:background="#fff"
5+
android:layout_height="wrap_content">
6+
7+
<TextView
8+
android:padding="20dp"
9+
android:text="Header"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content" />
12+
13+
<android.support.v7.widget.RecyclerView
14+
android:id="@+id/recyclerView"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"/>
17+
18+
<EditText
19+
android:layout_marginBottom="40dp"
20+
android:hint="输入"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content" />
23+
24+
25+
</LinearLayout>

0 commit comments

Comments
 (0)