我有這張底部表,我想在我的 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);
}
}
uj5u.com熱心網友回復:
你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();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/417824.html
標籤:
