将事物添加到Android DialogFragment的背景

时间:2019-05-06 14:30:42

标签: android kotlin android-dialogfragment

想在Dialog的背景中添加一些内容,例如

enter image description here

我试图阅读所有文档,但是找不到将check in文本添加到背景的方法。

2 个答案:

答案 0 :(得分:4)

我已经这样做了,希望对您有所帮助

Layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:calendar="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/mainLayout"
    android:layout_height="match_parent"
    android:layout_marginBottom="@dimen/fifty_five_dp"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/twenty_dp"
        android:layout_marginTop="@dimen/one_twenty_dp"
        android:layout_marginRight="@dimen/twenty_dp"
        calendar:cardCornerRadius="@dimen/three_dp"
        calendar:cardElevation="@dimen/two_dp"
        calendar:cardPreventCornerOverlap="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/fifty_five_dp"
            android:background="@color/dull_white"
            android:padding="@dimen/thirteen_dp"
            android:textSize="@dimen/sixteen_sp">

            <TextView
                android:id="@+id/leaveFromTo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:fontFamily="@font/sf_pro_display_bold"
                android:text="@string/select_leaves_placeholder"
                android:textColor="@color/darkGreyDeepDeep"
                android:textSize="@dimen/sixteen_sp" />

            <TextView
                android:id="@+id/leaveCount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:fontFamily="@font/sf_pro_display_bold"
                android:text="@string/days_placeholder"
                android:textColor="@color/darkGrey"
                android:textSize="@dimen/twelve_sp" />
        </RelativeLayout>
    </androidx.cardview.widget.CardView>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:calendar="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/seven_dp"
        android:layout_marginTop="@dimen/fifteen_dp"

        android:background="@drawable/box"
        android:padding="@dimen/ten_dp">

        <RelativeLayout
            android:id="@+id/okayLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/thirteen_dp">

            <ImageView
                android:id="@+id/calenderDrawable"
                android:layout_width="@dimen/seventeen_dp"
                android:layout_height="@dimen/seventeen_dp"
                android:layout_centerVertical="true"
                android:src="@mipmap/calener" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginStart="@dimen/ten_dp"
                android:layout_toRightOf="@+id/calenderDrawable"
                android:text="Calender"
                android:textColor="@color/blue_light"
                android:textSize="@dimen/fourteen_sp" />

            <Button
                android:id="@+id/btnDone"
                android:layout_width="@dimen/seventy_dp"
                android:layout_height="@dimen/twenty_six_dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_margin="@dimen/three_dp"
                android:background="@drawable/calender_button_background"
                android:text="DONE"
                android:textColor="@color/white"
                android:textSize="@dimen/thirteen_sp" />


        </RelativeLayout>

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@id/okayLayout"
            android:layout_marginTop="@dimen/ten_dp"
            android:background="@color/viewColor" />

        <com.neomeric.nock.com.andexert.calendarlistview.library.DayPickerView
            android:id="@+id/pickerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/view"
            android:layout_marginTop="@dimen/ten_dp"
            android:background="@color/dull_white"
            calendar:enablePreviousDay="false" />

    </RelativeLayout>

</LinearLayout>

DatePickerPopup.java

    public class DatePickerPopup extends DialogFragment implements DatePickerController {
    private DayPickerView dayPickerView; 

    public DatePickerPopup() {
        // Empty constructor is required for DialogFragment
        // Make sure not to add arguments to the constructor
        // Use `newInstance` instead as shown below
    }

    public static DatePickerPopup newInstance(OnDatesSelected datesSelected, Date first, Date last) {
        DatePickerPopup frag = new DatePickerPopup();
        Bundle args = new Bundle();
        frag.setArguments(args);
        return frag;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.date_selection_layout, container);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        return root;
    }

    public void setDateAndDaysCount(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays) {

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public int getMaxYear() {
        return 2021;
    }

    @Override
    public void onDayOfMonthSelected(int year, int month, int day) {


    }

    @Override
    public void onStart() {
        super.onStart();
        //  To make it match parent
        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    }

    @Override
    public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays) {

    }

}

How it looks

答案 1 :(得分:1)

制作具有2种内部布局的线性布局,其中上部布局具有透明的背景,而另一种具有内容。


library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
#> Registered S3 method overwritten by 'rvest':
#>   method            from
#>   read_xml.response xml2

data <- data.frame(letters=c("a","b","c"))

f <- c("^.","^a","^b")

map(f, ~filter(data, str_detect(letters, .x)))
#> [[1]]
#>   letters
#> 1       a
#> 2       b
#> 3       c
#> 
#> [[2]]
#>   letters
#> 1       a
#> 
#> [[3]]
#>   letters
#> 1       b