我一直在尝试使 DialogFragment 在左上角有一个关闭按钮,如图所示。 What the final result should look like (Sorry about the text, it's in romanian)谁能告诉我该怎么做?
这是 fragment 的布局:
<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="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="-50dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample Text"/>
<!---add your views here-->
</LinearLayout>
<ImageView
android:id="@+id/imageView_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:clickable="true"
android:src="@drawable/ic_close_dialog" />
fragment 现在的样子:A small box where the image and text are overlayed
最佳答案
您可以创建自定义布局并使用
dialog.setContentView(R.layout.custom_view);
引用custom dialog with close button
如果仍然像图片中那样,则可能是此约束布局的容器 View 将wrap_content作为其宽度和高度。
关于android - 向 DialogFragment 添加关闭按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52041014/