Home > Mobile >  AlertDialog with setView is too tall
AlertDialog with setView is too tall

Time:12-21

I'm making an app and want to integrate donations since it's free and has no ads. I'm trying to add an AlertDialog with a QR code and a positive button. When I use this code, though, the AlertDialog is too tall (looks ugly), and you can't press the button. What can I do? Thanks.

enter image description here

            val inflater = this.layoutInflater
            val dialogView = inflater.inflate(R.layout.btc_layout, null)
            val builder: AlertDialog? =
                AlertDialog.Builder(this).setMessage("Click copy to copy the Bitcoin address to your clipboard")

                    .setPositiveButton("copy"){ dialog, which ->
                        val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
                        val address = ClipData.newPlainText("text", "3KekRCkMo7pC9Rd1u5JtQQPdxnXD1cUfnM")
                        clipboardManager.setPrimaryClip(address)

                        Toast.makeText(
                            this@donations,
                            "copied!",
                            Toast.LENGTH_SHORT
                        ).show()

                    }.setView(dialogView).show()

this is btc_layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/btc">
    </ImageView>

</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

I figured it out. I just set the layout_gravity in the XML file to center, and changed the width and height to match the AlertDialog.

CodePudding user response:

It is not your code, it is the ImageView by itself

A possible issue (I have personally had the same issue), I believe that the ImageView tends to set the height to be parent, no matter what is declared. I would try specify the height and width of the ImageView to something like like 100dp by 100dp or larger or to your specifications.

  • Related