[英]Bottom sheet not inflating in activity
我有这张底部表,我想在我的 DialogsActivity.java 中单击按钮时充气,但是每当我运行我的应用程序并单击按钮时,什么都没有发生。
这是应该膨胀底部工作表的代码。
DialogsActivity.java
floatingButtonContainer = new FrameLayout(context);
floatingButtonContainer.setVisibility(onlySelect && initialDialogsType != 10 || folderId != 0 ? View.GONE : View.VISIBLE);
contentView.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
floatingButtonContainer.setOnClickListener(v -> {
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
inflater.inflate(R.layout.fragment_bottom_sheet,null);
});
这是 BottomSheetFrag.java
public class BottomSheetFrag extends BottomSheetDialogFragment {
public BottomSheetFrag(){
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
//return super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
}
}
您的BottomSheetFrag
代码看起来不错。
您不需要在活动中膨胀BottomSheetFrag
,而是应该为此目的使用Fragment Transaction
。
请如下更新您的DialogActivity
代码。
BottomSheetFrag bottomSheet = new BottomSheetFrag();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.executePendingTransactions();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (bottomSheet.isAdded()) {
FragmentTransaction removeTransaction = fragmentManager.beginTransaction();
removeTransaction.remove(bottomSheet);
removeTransaction.commitNow();
}
fragmentTransaction.add(bottomSheet, "tag");
fragmentTransaction.commitNow();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.