1 BottomSheetDialog 底部弹出框
BottomSheetDialog的简单使用:
/**
* func:弹出举报dialog
*/
private void showShieldDialog(long articleId,int articleType) {
if (getActivity() == null) return;
if (sheildDialog != null && sheildDialog.isShowing()) {
sheildDialog.dismiss();
}
sheildDialog = new BottomSheetDialog(getActivity(), R.style.BottomSheetEdit);
View tCommentView = LayoutInflater.from(getActivity()).inflate(R.layout.community_sheild_layout, null);
final TextView notSeeDynamic = tCommentView.findViewById(R.id.bottom_view_not_see_dynamic);
final TextView notSeeUser = tCommentView.findViewById(R.id.bottom_view_not_see_user);
final TextView shield = tCommentView.findViewById(R.id.bottom_view_shield);
final TextView cancle = tCommentView.findViewById(R.id.bottom_view_cancle);
sheildDialog.setContentView(tCommentView);
cancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sheildDialog.dismiss();
}
});
notSeeDynamic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sheildDialog.dismiss();
}
});
notSeeUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sheildDialog.dismiss();
}
});
shield.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sheildDialog.dismiss();
}
});
sheildDialog.show();
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/bottom_view_not_see_dynamic"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="不再查看此条动态"
android:textSize="18sp"
android:textColor="#FF000000"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFF2F2F2">
</View>
<TextView
android:id="@+id/bottom_view_not_see_user"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="不再查看此人动态"
android:textSize="18sp"
android:textColor="#FF000000"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFF2F2F2">
</View>
<TextView
android:id="@+id/bottom_view_shield"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="投诉"
android:textSize="18sp"
android:textColor="#FF000000"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="#FFF2F2F2">
</View>
<TextView
android:id="@+id/bottom_view_cancle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="取消"
android:textSize="18sp"
android:textColor="#FF000000"
android:gravity="center"/>
</LinearLayout>
//style
<style name="BottomSheetEdit" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
2 键盘遮挡问题
BottomSheetDialog中存在一个editText时,当软键盘出现后,键盘会覆盖焦点以下的dialog,
private void showCommentDialog2() {
BottomSheetDialog dialog2 = new BottomSheetDialog(this);
View commentView = LayoutInflater.from(this).inflate(R.layout.select_car_keyboard2, null);
dialog2.setContentView(commentView);
dialog2.show();
}
解决可以利用ajustResize会重新布局当前窗口,且需要当前dialog不是浮动的。
解决方案:为创建的bottomSheetDialog设置自定style,代码如下
<style name="BottomSheetEdit" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetEdit);
解决代码:
private void showCommentDialog2() {
BottomSheetDialog dialog2 = new BottomSheetDialog(this, R.style.BottomSheetEdit);
// BottomSheetDialog dialog2 = new BottomSheetDialog(this);
View commentView = LayoutInflater.from(this).inflate(R.layout.select_car_keyboard2, null);
dialog2.setContentView(commentView);
dialog2.show();
}
特别注意:其实我们仔细 观察,还是可以发现BottomSheetDialog设置了style后,底部依然会被遮挡。