迁移到androidx后,自定义弹出对话框不起作用。 这就是我编写弹出对话框布局的方式,如果您的回答是友善地解释了此问题的原因,那么在迁移到androidx之前一切工作都很好。初始化此对话框时只显示透明屏幕。
popupdialogSR.setContentView(R.layout.popup_subscribe);
buyQr = popupdialogSR.findViewById(R.id.buttonBuyQr);
scanQr = popupdialogSR.findViewById(R.id.buttonScanQr);
gPay = popupdialogSR.findViewById(R.id.buttonGPAY);
popupdialogSR.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupdialogSR.show();
布局,
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginEnd="@dimen/_8sdp"
android:gravity="center">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginTop="@dimen/_8sdp"
android:layout_marginEnd="@dimen/_8sdp"
android:layout_marginBottom="@dimen/_8sdp"
android:background="@color/colorWhite"
app:cardCornerRadius="8dp"
app:cardElevation="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="@dimen/_270sdp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/overlay_darkblur">
<ImageView
android:id="@+id/imageView3"
android:layout_width="@dimen/_160sdp"
android:layout_height="@dimen/_80sdp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/_20sdp"
android:layout_marginBottom="8dp"
android:padding="@dimen/_10sdp"
android:src="@drawable/applogo"
app:layout_constraintBottom_toTopOf="@id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:layout_gravity="center_horizontal|center"
android:gravity="center"
android:paddingStart="@dimen/_15sdp"
android:paddingEnd="@dimen/_15sdp"
android:text="@string/subscibe_popupcontent"
android:textSize="@dimen/_12sdp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView3"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/buttonBuyQr"
android:layout_width="@dimen/_60sdp"
android:layout_height="@dimen/_30sdp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="@dimen/_8sdp"
android:layout_marginBottom="@dimen/_25sdp"
android:background="@drawable/button_savechanges"
android:text="@string/buy_qr"
android:textAllCaps="false"
android:textSize="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/buttonScanQr"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/buttonScanQr"
android:layout_width="@dimen/_60sdp"
android:layout_height="@dimen/_30sdp"
android:layout_marginStart="@dimen/_4sdp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="@dimen/_25sdp"
android:background="@drawable/button_savechanges"
android:text="@string/scan_qr"
android:textAllCaps="false"
android:textSize="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.0" />
<ImageButton
android:id="@+id/buttonGPAY"
android:layout_width="@dimen/_60sdp"
android:layout_height="@dimen/_30sdp"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginTop="16dp"
android:layout_marginEnd="@dimen/_4sdp"
android:layout_marginBottom="@dimen/_25sdp"
android:src="@drawable/google_payicon"
android:background="@drawable/button_signin"
android:scaleType="fitCenter"
android:elevation="11dp"
android:textAllCaps="false"
android:textSize="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/buttonScanQr"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
答案 0 :(得分:0)
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
popupdialogSR = new Dialog(mContext);
popupdialogSR.setContentView(R.layout.popup_subscribe);
popupdialogSR.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
buyQr = popupdialogSR.findViewById(R.id.buttonBuyQr);
scanQr = popupdialogSR.findViewById(R.id.buttonScanQr);
gPay = popupdialogSR.findViewById(R.id.buttonGPAY);
如果这也行不通,请发布您的布局
答案 1 :(得分:0)
在XML布局中,我只是将hieght和width更改为自定义大小,效果很好
<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="@dimen/_260sdp"
android:layout_height="@dimen/_220sdp"