Kya*_*ant 5 android android-layout android-bottomsheetdialog
我只想得到BottomSheetDialog如下内容:系统窗口中的边距。我怎么会变成这样?
and*_*oid 19
您可以通过以下方式创建底部工作表对话框片段:
首先创建如下命名的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="@dimen/_150sdp"
android:layout_margin="@dimen/_20sdp"
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="@dimen/_10sdp"
android:layout_alignParentBottom="true"
android:paddingBottom="@dimen/_10sdp"
android:paddingTop="@dimen/_10sdp"
android:text="Select Address" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
现在创建一个名为
底部片断
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));
}
}
Run Code Online (Sandbox Code Playgroud)
要调用该底部工作表片段,您可以编写如下:
BottomSheetFragment bottomSheetDialog = BottomSheetFragment.newInstance();
bottomSheetDialog.show(getSupportFragmentManager(), "Bottom Sheet Dialog Fragment");
Run Code Online (Sandbox Code Playgroud)
我现在只使用了一个 textview 并附上了屏幕截图,因为您主要关心的是在底部表格中获得边距。同样通过这种方式,您可以根据需要自定义底部工作表。谢谢!

| 归档时间: |
|
| 查看次数: |
10803 次 |
| 最近记录: |