BottomSheetDialogFragment高仿抖音评论底部弹出框
先看效果图:
这个弹窗的效果是使用BottomSheetDialogFragment做的,第一个弹出的对话框为CommentListDialogFragment ,第二个弹出的对话框为SendCommentDialogFragment,代码如下:
展示 CommentListDialogFragment
。
public class CommentListDialogFragment extends BottomSheetDialogFragment {
private Dialog dialog;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.DialogTheme);//给dialog设置主题为透明背景 不然会有默认的白色背景
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
dialog = super.onCreateDialog(savedInstanceState);
dialog.setCanceledOnTouchOutside(true);//设置点击外部可消失
Window win = dialog.getWindow();
WindowManager.LayoutParams params = win.getAttributes();
win.setSoftInputMode(params.SOFT_INPUT_ADJUST_NOTHING);//设置使软键盘弹出的时候dialog不会被顶起
win.setWindowAnimations(R.style.Anim_Dialog_Bottom);//这里设置dialog的进出动画
return dialog;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// 在这里将view的高度设置为精确高度,即可屏蔽向上滑动不占全屏的手势。如果不设置高度的话 会默认向上滑动时dialog覆盖全屏
View view = inflater.inflate(R.layout.list_dialog, container, false);
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
getScreenHeight(getActivity()) * 2 / 3));
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
TextView postCommentText = view.findViewById(R.id.tv);
RecyclerView recyclerView = view.findViewById(