Remove title from DialogFragment

被刻印的时光 ゝ 提交于 2021-01-28 04:13:25

问题


Still I'm notgetting answer from this site.... Time to left this world.

I have made a DialogFragment which shows the profile of the user but it has a top title show. When I use getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); then the card that I have shown on the dialog CardView disappears and show the simple detail.

When I don't use getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); DialogFragment show like this

When use getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); DialogFragment show like this

I want the title to be removed and the background to remain.

Here is my Code

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (_main == null) _main = (MainActivity) getActivity();
    context = _main;

    View v = inflater.inflate(R.layout.fragprofile, container, false);

    layProfile = (ConstraintLayout) v.findViewById(R.id.layProfile);
    txtID = v.findViewById(R.id.txtID);
    txtUserID = v.findViewById(R.id.txtBenutzername);
    txtName = v.findViewById(R.id.txtName);
    txtAdresse = v.findViewById(R.id.txtAdresse);
    lineAdresse = v.findViewById(R.id.lineAdresse);
    txtFocusOfWork = v.findViewById(R.id.txtFocusOfWork);
    lineFocusOfWork = v.findViewById(R.id.lineFocusOfWork);
    txtOnlineState = v.findViewById(R.id.txtOnlineState);
    imgProfileBlurred = v.findViewById(R.id.imgProfileBlurred);
    imgProfileCircle = v.findViewById(R.id.imgProfileCircle);
    btnPhone = (TextView) v.findViewById(R.id.btnPhone);
    linePhone = v.findViewById(R.id.linePhone);
    btnEMail = (TextView) v.findViewById(R.id.btnEMail);
    lineEMail = v.findViewById(R.id.lineEMail);
    btnWhatsApp = (ImageView) v.findViewById(R.id.btnWhatsApp);

    if (this.BenutzerName != null) {
        try {
            setValuesTextAndImage(this.BenutzerID, this.BenutzerName);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            lib.ShowException(TAG, context, throwable, false);
        }
    }

   Objects.requireNonNull(getDialog()).getWindow().setBackgroundDrawableResource(R.drawable.bg_round_corner);
    return v;
}

XML

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
tools:context="de.com.limto.limto1.dlgProfile">

<ImageView
    android:id="@+id/imgProfileBlurred"
    android:layout_width="0dp"
    android:layout_height="200dp"
    android:scaleType="centerCrop"
    android:src="@drawable/vn_logo_c02"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/txtID"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:gravity="center"
    android:hint="@string/ID"
    android:shadowColor="#000000"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.imageview.ShapeableImageView
    android:id="@+id/imgProfileCircle"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginTop="4dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    app:layout_constraintEnd_toStartOf="@id/txtOnlineState"
    app:layout_constraintHorizontal_bias="0.179"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/txtID"
    app:shapeAppearanceOverlay="@style/roundedImageViewRounded"
    app:srcCompat="@drawable/ic_launcher_background" />

<TextView
    android:id="@+id/txtOnlineState"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:hint="@string/onlinestate"
    android:shadowColor="#000000"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="@id/imgProfileBlurred"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/txtName"
    app:layout_constraintVertical_bias="0.873" />

<TextView
    android:id="@+id/txtBenutzername"
    style="@style/TextAppearance.AppCompat.Title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp"
    android:hint="@string/Benutzername"
    android:shadowColor="#000000"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:textColor="@android:color/white"
    app:layout_constraintBottom_toTopOf="@+id/txtName"
    app:layout_constraintStart_toEndOf="@+id/imgProfileCircle"
    app:layout_constraintTop_toTopOf="@+id/imgProfileCircle" />

<TextView
    android:id="@+id/txtName"
    style="@style/TextAppearance.AppCompat.Body1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/name2"
    android:shadowColor="#000000"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    app:layout_constraintBottom_toBottomOf="@+id/imgProfileCircle"
    app:layout_constraintStart_toStartOf="@id/txtBenutzername"
    app:layout_constraintTop_toBottomOf="@id/txtBenutzername" />

<TextView
    android:id="@+id/txtAdresse"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:drawablePadding="32dp"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:text="@string/Adresse"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:drawableStartCompat="@drawable/ic_adress"
    app:layout_constraintTop_toBottomOf="@id/imgProfileBlurred" />

<View
    android:id="@+id/lineAdresse"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:background="#c0c0c0"
    app:layout_constraintTop_toBottomOf="@id/txtAdresse" />


<TextView
    android:id="@+id/txtFocusOfWork"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:drawablePadding="32dp"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:text="@string/Taetigkeitsschwerpunkte"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:drawableStartCompat="@drawable/ic_work"
    app:layout_constraintTop_toBottomOf="@id/lineAdresse" />

<View
    android:id="@+id/lineFocusOfWork"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:background="#c0c0c0"
    app:layout_constraintTop_toBottomOf="@id/txtFocusOfWork" />

<TextView
    android:id="@+id/btnPhone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:drawablePadding="32dp"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:text="@string/phone"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:drawableStartCompat="@drawable/ic_phone"
    app:layout_constraintStart_toStartOf="@id/txtFocusOfWork"
    app:layout_constraintTop_toBottomOf="@id/lineFocusOfWork" />

<ImageView
    android:id="@+id/btnWhatsApp"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginStart="@dimen/dialog_vertical_margin"
    android:layout_marginLeft="@dimen/dialog_vertical_margin"
    android:layout_marginTop="@dimen/dialog_horizontal_margin"
    android:contentDescription="@string/whatsapp"
    android:src="@drawable/cc"
    app:layout_constraintBottom_toTopOf="@id/linePhone"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0"
    app:layout_constraintStart_toEndOf="@id/btnPhone"
    app:layout_constraintTop_toBottomOf="@id/lineFocusOfWork" />


<View
    android:id="@+id/linePhone"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:background="#c0c0c0"
    app:layout_constraintTop_toBottomOf="@id/btnPhone" />

<TextView
    android:id="@+id/btnEMail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:drawablePadding="32dp"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:text="@string/prompt_email"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:drawableStartCompat="@drawable/ic_email"
    app:layout_constraintTop_toBottomOf="@id/linePhone" />

<View
    android:id="@+id/lineEMail"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:background="#c0c0c0"
    app:layout_constraintTop_toBottomOf="@id/btnEMail" />

</androidx.constraintlayout.widget.ConstraintLayout>

R.drawable.bg_round_corner

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF" />
    <corners android:radius="20dp" />
</shape>

来源:https://stackoverflow.com/questions/65708263/remove-title-from-dialogfragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!