Show a layout as popup after click on button

Hi,

I need some help.
I try to show a custom popup layout (it’s a constraint layout) after click on a button.
But i face some difficulties.

If someone can help me?

Thanks a lot

Generally it helps if you can show some of the code you have problems with (just a short snippet 5-10 lines that are relevant). How do you try to create the popup? What error messages do you get?

You say you are rusing a constraint layout, I’m guessing this is on Android? If so, this is good for us to know so we can help you. There are probably hundreds if not thousand different ways to solve your problem (based on what platform you develop for and what libraries you use, eg. android, ios, desktop, web, etc)

As Wasabi mentioned, your question is currently very general, and so I can only provide a general answer. To show a pop-up on Android people usually use a DialogFragment populated with the needed layout (in your case the constraint layout). You basically construct the DialogFragment then call .show() on it, Also, see this Android doc for more info: https://developer.android.com/guide/fragments/dialogs

Hello Wasabi and Kyay, you’re right.
I give you more details.

It’s my layout Popupfragment:

class PopupWindow(
private val StartFrag: StartFragment
) : Dialog(StartFrag.context!!) {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    requestWindowFeature(Window.FEATURE_NO_TITLE)
    setContentView(R.layout.fragment_popup)
}

}

I create a xml popup layout with special color, font, picture, etc…

And i want to show the popup (or layout) above the fragment “StartFragment” after click on a button on this layout.

My Start fragment code below:

class StartFragment(
private val context: MainActivity) : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    return inflater?.inflate(R.layout.fragment_start, container, false)

    ButtonStart.setOnClickListener {
    PopupWindow(this).show()
    }
   }
}

For your info, i display a navigation bar below the app.

Do you have enough details ?

Thanks for your help! i’m stuck :frowning:

I dont have any error, but when i click on the button, nothing happens.