Добавьте вещи на фоне Android DialogFragment - PullRequest
2 голосов
/ 06 мая 2019

Хотите добавить что-то на задний план Диалога, например

enter image description here

Я пытался прочитать все документы, но не могу найти способ добавить check in текст на задний план.

Ответы [ 2 ]

4 голосов
/ 14 мая 2019

Я сделал это так, надеюсь, это поможет

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) {

    }

}

Как это выглядит

1 голос
/ 09 мая 2019

Создайте линейный макет с двумя внутренними макетами, где верхний будет иметь прозрачный фон, а другой - контент.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/transparent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            app:srcCompat="@drawable/ic_clock" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_margin="10dp"
        android:background="#000000"
        android:orientation="vertical">

    </LinearLayout>

</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...