1 回答

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
在您添加的屏幕截圖中,我看到了類似 BottomSheet 的內(nèi)容。為了獲得這種對話框的外觀,您可能想要使用,BottomSheetDialogFragment所以下面我將解釋如何在您的活動(dòng)中實(shí)現(xiàn)它。
1) 首先,您需要?jiǎng)?chuàng)建一個(gè)類,該類將從BottomSheetDialogFragment該片段將使用的布局?jǐn)U展并擴(kuò)充該布局。
public class ExampleBottomSheetDialog extends BottomSheetDialogFragment {
? ? @Override
? ? public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle?
savedInstanceState) {
? ? ? ? return inflater.inflate(*R.layout.bottom_sheet_layout*, container, false);
? ? }
}
2)然后您需要?jiǎng)?chuàng)建*R.layout.bottom_sheet_layout*布局文件來保存所需的視圖并在需要時(shí)為其提供邏輯。
3) 之后,您可以通過編程方式設(shè)置Dialog邏輯。例如,您可以通過按 按鈕打開此對話框。
Button buttonDialogBottomSheet = findViewById(R.id.btn_sh_dialog);
buttonDialogBottomSheet.setOnClickListener((v) -> {
? ? ExampleBottomSheetDialog bottomSheetDialog = new ExampleBottomSheetDialog();
? ? bottomSheetDialog.show(getSupportFragmentManager(), "simple tag");
});
添加回答
舉報(bào)