[英]Bottom sheet not inflating in activity
I have this bottom sheet that i wanted to inflate on button click in my DialogsActivity.java but whenever i run my app and click the button nothing happens.我有这张底部表,我想在我的 DialogsActivity.java 中单击按钮时充气,但是每当我运行我的应用程序并单击按钮时,什么都没有发生。
this is the code where it should've inflated the bottom sheet.这是应该膨胀底部工作表的代码。
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);
});
This is the BottomSheetFrag.java这是 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);
}
}
You BottomSheetFrag
code looks fine.您的
BottomSheetFrag
代码看起来不错。
You dont need to inflate BottomSheetFrag
in activity, instead you should use Fragment Transaction
for this purpose.您不需要在活动中膨胀
BottomSheetFrag
,而是应该为此目的使用Fragment Transaction
。
Please update your DialogActivity
code as below.请如下更新您的
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.