Прозрачный фон макета заголовка BottomSheetDialogFragment не работает - PullRequest
0 голосов
/ 06 марта 2020

Я создал BottomSheetFragment. После нажатия на кнопку он появится. Все хорошо, кроме черной части нижнего листа, которая не становится прозрачной. Я попытался, установив родительский фон прозрачным, но он не работает вообще. Примечание: я использовал черный цвет для обозначения части, которая должна быть прозрачной.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="350dp"
android:layout_height="600dp"
android:id="@+id/layoutContainer"
android:background="@android:color/transparent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/immediateParent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="10">
        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/zero"
            android:layout_weight="2" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/zero"
            android:layout_weight="8"
            android:background="@drawable/white_top_rounded_bg">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:weightSum="10.01">
                <View
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/zero"
                    android:layout_weight="1.5" />
                <android.support.v4.widget.NestedScrollView
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/zero"
                    android:layout_weight="7.5">
                </android.support.v4.widget.NestedScrollView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    <com.makeramen.roundedimageview.RoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/rivInfoProfileSecond"
        android:layout_width="@dimen/hundrad_twenty"
        android:layout_height="@dimen/hundrad_twenty"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/sixty"
        android:scaleType="centerCrop"
        android:src="@drawable/download"
        app:riv_border_color="@color/transparent"
        app:riv_corner_radius="@dimen/twenty"
        app:riv_mutate_background="true"
        app:riv_oval="false" />
    <ImageView
        android:layout_width="@dimen/thirty"
        android:layout_height="@dimen/thirty"
        android:layout_alignParentRight="true"
        android:layout_marginTop="@dimen/hundred_fifty"
        android:layout_marginRight="100dp"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_plus_profile_photo_icon" />
</RelativeLayout>

Я устал от этого.

ConstraintLayout layoutContainer;
RelativeLayout immediateParent;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = null;
    view = inflater.inflate(R.layout.bottom_sheet_dialog, container);
    ButterKnife.bind(this, view);
    //parent layout transparent not working
    layoutContainer.setBackground(getResources().getDrawable(R.color.transparent));

    immediateParent.setBackground(getResources().getDrawable(R.color.transparent));
    //view transparent 
    view.setBackgroundColor(getResources().getColor(R.color.transparent));
    return view;
}

Вот изображение, приведенное ниже.

This is how the UI looks like

Ответы [ 2 ]

0 голосов
/ 07 марта 2020

После стольких попыток я нашел свое решение. Просто добавил этот код в мой фрагмент.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ((View) getView().getParent()).setBackgroundColor(Color.TRANSPARENT);
}

BottomSheetDialog с прозрачным фоном

0 голосов
/ 07 марта 2020

Ваше представление на самом деле прозрачное (когда вы используете прозрачный вместо черного, очевидно), проблема в том, что BottomSheetDialogFragment упаковывает ваше представление в свой непрозрачный контейнер. Вот как сделать этот контейнер прозрачным: { ссылка }

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