import android.app.Dialog;
t.Context;
aphics.Color;
aphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
dinatorlayout.widget.CoordinatorLayout;
lerview.widget.GridLayoutManager;
lerview.widget.RecyclerView;
le.android.material.bottomsheet.BottomSheetBehavior;
le.android.material.bottomsheet.BottomSheetDialog;
le.android.material.bottomsheet.BottomSheetDialogFragment; import java.util.ArrayList;
import java.util.List;
/**
* @Author: david.lvfujiang
* @Date: 2019/11/14
* @Describe:
*/
public class BaseFullBottomSheetFragment extends BottomSheetDialogFragment { private List mShareList = new ArrayList<>();
田馥甄图片private int[] imgArry= {R.mipmap.five,R.mipmap.four,,R.mipmap.three}; private Context mContext;
private View view;
public static BaseFullBottomSheetFragment getInstance() {
return new BaseFullBottomSheetFragment();
}
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Log.e("TAG", "onCreateDialog: ");
//返回BottomSheetDialog的实例
李宗盛女儿return new Context());
}
@Override
public void onStart() {
Log.e("TAG", "onStart: ");
//获取dialog对象
三月你好的心情说说BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
/
/把windowsd的默认背景颜⾊去掉,不然圆⾓显⽰不见
ColorDrawable(Color.TRANSPARENT));
//获取diglog的根部
FrameLayout bottomSheet = Delegate().findViewById(R.id.design_bottom_sheet);
if (bottomSheet != null) {
//获取根部局的LayoutParams对象
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) LayoutParams(); layoutParams.height = getPeekHeight();
//修改弹窗的最⼤⾼度,不允许上滑(默认可以上滑)
bottomSheet.setLayoutParams(layoutParams);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
//peekHeight即弹窗的最⼤⾼度
behavior.setPeekHeight(getPeekHeight());
// 初始为展开状态春节高速什么时候开始免费
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
ImageView mReBack = view.findViewById(_back_img);
//设置监听
mReBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
});
}
}
/**
* 弹窗⾼度,默认为屏幕⾼度的四分之三
* ⼦类可重写该⽅法返回peekHeight柔顺剂怎么用
*
* @return height
*/
protected int getPeekHeight() {
int peekHeight = getResources().getDisplayMetrics().heightPixels;
/
/设置弹窗⾼度为屏幕⾼度的3/4
return peekHeight - peekHeight / 3;
红烧肉的做法视频}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { mContext = getContext();
Log.e("TAG", "onCreateView: ");
view = inflater.inflate(R.layout.layoyt_bottomsheet, container, false);
initData();
initViews(view);
return view;
}
private void initViews(View view) {
RecyclerView recyclerView = view.findViewById(R.id.fragment_share_recyclerView);
recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
RecyclerCommonAdapter adapter = new RecyclerCommonAdapter(lear_item, mShareList);
recyclerView.setAdapter(adapter);
}
private void initData() {
for (int i = 0; i < 30; i++) {
ShareItem item = new ShareItem();
item.setIcon(imgArry[i%4]);
mShareList.add(item);
}
}
}
有以下⼏点需要注意:1.去掉窗⼝的background,窗⼝的background默认是⽩⾊的,如果不处理我们的根部局设置圆⾓背景的时候是没有效果的
(new ColorDrawable
(Color.TRANSPARENT));
2.固定窗⼝的⾼度,窗⼝默认可以向上滑动直到铺满整个屏幕RecyclerView才开始滑动
BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
//把windowsd的默认背景颜⾊去掉,不然圆⾓显⽰不见
ColorDrawable(Color.TRANSPARENT));
//获取diglog的根部局
FrameLayout bottomSheet = Delegate().findViewById(R.id.design_bottom_sheet);
if (bottomSheet != null) {
//获取根部局的LayoutParams对象
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) LayoutParams();
layoutParams.height = getPeekHeight();
//修改弹窗的最⼤⾼度,不允许上滑(默认可以上滑)
bottomSheet.setLayoutParams(layoutParams);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
//peekHeight即弹窗的最⼤⾼度
behavior.setPeekHeight(getPeekHeight());
// 初始为展开状态
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
ImageView mReBack = view.findViewById(_back_img);
//设置监听
mReBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {