簡體   English   中英

底部床單在活動中沒有膨脹

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM