I'm creating an mobile app on Android Studio, and I have a list of shows where, if I click on one of them, it displays a popup with all informations on the clicked show.
I'm creating my popup like this :
class ShowPopup(private val adapter : ShowAdapter, private val currentShow : ShowModel) : Dialog(adapter.context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.popup_show_details)
setupComponents() // Define the values of each fields of the popup
}
And here I show the popup on click:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// Get show info
val currentShow = showList[position]
holder.itemView.setOnClickListener{
ShowPopup(this, currentShow).show()
}
}
My issue here is that, when clicking on the show, my popup only takes a small amount of space. I tried setting the width
and height
of my popup layout but it doesn't take full screen, even if I go past my screen size, I just don't get all content displayed...I'd be grateful if someone could explain how I could achieve putting my popup fullscreen. Thank you in advance !
Here is my layout code :
<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:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Popup content -->
</androidx.constraintlayout.widget.ConstraintLayout>
CodePudding user response:
You can add this piece of code to your dialog class
override fun onStart() {
super.onStart()
window?.apply {
setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
}
To be honest, fullscreen dialogs are always pain in.. you know. But this fix does always work for me. You can also take a look at this post, it has plenty ways and a lot of discussed stuff.