自定义底页对话框的视图 [英] Customization Bottom Sheet Dialog's View

查看:90
本文介绍了自定义底页对话框的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想从系统窗口中获取下面的对话框,如below_:margin.我怎么能这样?

I just want to get the bottom sheet dialog like below_: margin from the system window. How can I get like this?

推荐答案

您可以通过以下方式创建底表"对话框片段:

You can create Bottom Sheet Dialog Fragment in following way:

首先创建如下名为

fragment_bottomsheet

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>

现在创建一个名为

BottomSheetFragment

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));
    }

}

要调用该底页片段,您可以编写以下内容:

To call that bottom sheet fragment you can write as below:

BottomSheetFragment bottomSheetDialog = BottomSheetFragment.newInstance();
bottomSheetDialog.show(getSupportFragmentManager(), "Bottom Sheet Dialog Fragment");

我现在只进行了一个textview并附加了屏幕截图,因为您主要关心的是在底页中留有余地.同样,您可以根据需要自定义底部工作表.谢谢!

I have only took a single textview for now and attaching the screenshot because your main concern is to get margin in bottomsheet. Also in this way you can customize bottom sheet as you want. Thanks!

这篇关于自定义底页对话框的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆