【发布时间】:2021-09-22 10:58:42
【问题描述】:
您好,我有一个 bottomsheet 和一些 textViews(作为按钮),当按下它时它会导航到一个不同的片段,但问题是当按下 textView 并导航到片段时,底部的工作表仍然没有隐藏点击屏幕以隐藏底部工作表,我希望在启动片段时底部工作表将隐藏,这是我遇到的问题的屏幕记录link
Profile_Fragment.java
ImageView accountSettings = view.findViewById(R.id.account_Settings);
accountSettings.setOnClickListener(
v -> {
BottomSheet bottomSheet = new BottomSheet();
bottomSheet.show(requireActivity().getSupportFragmentManager(), bottomSheet.getTag());
}
);
BottomSheet.java
public class BottomSheet extends BottomSheetDialogFragment {
public BottomSheet() {
}
@Nullable
@org.jetbrains.annotations.Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bottom_sheet_profile, container, false);
TextView settingsProfileTextView = view.findViewById(R.id.settings);
settingsProfileTextView.setOnClickListener(v -> {
Fragment settings_profile = new Settings_Profile();
FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, settings_profile);
transaction.addToBackStack(String.valueOf(settings_profile));
transaction.commit();
});
TextView editProfileTextView = view.findViewById(R.id.edit_profile);
editProfileTextView.setOnClickListener(v -> {
Fragment edit_profile = new Edit_Profile();
FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, edit_profile);
transaction.addToBackStack(String.valueOf(edit_profile));
transaction.commit();
});
return view;
}
}
Edit_Profile.java // 按下 textView 时正在打开的片段
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_edit_profile, container, false);
profilePhoto = view.findViewById(R.id.circleImageView);
initImageLoader();
setProfileImage();
ImageView imageView = view.findViewById(R.id.backArrow);
imageView.setOnClickListener(v -> {
Fragment newCase = new Profile_Fragment();
assert getFragmentManager() != null;
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newCase);
transaction.disallowAddToBackStack();
transaction.commit();
});
return view;
}
【问题讨论】:
-
在 settingsProfileTextView 点击监听器中的 transaction.commit() 之前添加这些行。 mBottomSheetBehavior.setHideable(true); mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
-
对不起,我添加了它,但它不起作用
标签: android android-fragments bottom-sheet android-bottomsheetdialog