android - 如何从 BottomSheet 打开片段
问题描述
您好,我已经实现了一个bottomsheetdilooge,我希望当在底部表中按下textview时,应该打开一个片段,请您告诉我如何实现它并且还想添加BackStack,当按下注销时我想打开一个dilouge而不是片段
这是我的代码
Profile_Fragment.java // 单击 imageview 时底部表打开的位置
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile, container, false);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
view.findViewById(R.id.snipet_profile);
ImageView accountSettings = view.findViewById(R.id.account_Settings);
// i open the bottom sheet when the imageview is clicked
accountSettings.setOnClickListener(
v -> {
BottomSheet bottomSheet = new BottomSheet();
bottomSheet.show(requireActivity().getSupportFragmentManager(), "ModalBottomSheet");
}
);
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) {
return inflater.inflate(R.layout.bottom_sheet_profile, container, false);
}
}
bottom_sheet_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:id="@+id/slidedownview"
android:layout_width="40dp"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="@drawable/rounded_corner_bottomsheetline"
android:layout_marginTop="11dp"/>
<TextView
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/slidedownview"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:text="@string/settings"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="@+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/settings"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="@string/edit_profile"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_profile"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="@string/favorite"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="@+id/log_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/favorite"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:layout_marginBottom="15dp"
android:elevation="10dp"
android:text="@string/log_out"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="normal" />
</RelativeLayout>
解决方案
推荐阅读
- javascript - XHR Get 请求不加载从 Express 应用程序接收到的 HTML 字符串
- java - 在具有多个操作的方法中使用 Spring @Transactional
- reactjs - 反应钩子混乱
- maven - 从 maven 依赖继承子依赖
- matlab - 使用 Matlab fitcdiscr 的 LDA 系数
- spartacus-storefront - 登录后强制 NavigationNodes 刷新
- react-native - 如何在排毒测试中从 RNN 中识别导航选项卡按钮
- python - 使用“python -c”控制台命令模式实现for循环
- r - 量词可以用于R中的正则表达式替换吗?
- c - C - 打印文本拆分为多行的奇怪问题?