gpt4 book ai didi

android - 自定义底页对话框的 View

转载 作者:行者123 更新时间:2023-12-03 15:11:54 26 4
gpt4 key购买 nike

我只想得到 BottomSheetDialog如下所示:系统窗口的边距。我怎么会变成这样?
enter image description here

最佳答案

您可以通过以下方式创建底页对话框 fragment :
首先创建如下命名的xml文件

fragment_bottomsheet

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="20dp"
android:background="@drawable/round_corner_white3"
android:orientation="vertical">

<TextView
android:id="@+id/tv_select_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/white"
android:background="@drawable/round_corner_gray"
android:layout_margin="10dp"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Select Address" />

</RelativeLayout>

</RelativeLayout>
现在创建一个名为的底部工作表 fragment

BottomSheetFragment

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.View;

public class BottomSheetFragment extends BottomSheetDialogFragment {

public static BottomSheetFragment newInstance() {
BottomSheetFragment fragment = new BottomSheetFragment();
return fragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void setupDialog(Dialog dialog, int style) {
View contentView = View.inflate(getContext(), R.layout.fragment_bottomsheet, null);
dialog.setContentView(contentView);
((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
}

}
要调用该底部工作表 fragment ,您可以编写如下:
BottomSheetFragment bottomSheetDialog = BottomSheetFragment.newInstance();
bottomSheetDialog.show(getSupportFragmentManager(), "Bottom Sheet Dialog Fragment");
我现在只使用了一个 TextView 并附上了屏幕截图,因为您主要关心的是在底页中获得边距。同样通过这种方式,您可以根据需要自定义底页。谢谢!
enter image description here

关于android - 自定义底页对话框的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55218663/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com