Skip to content
Advertisement

Can’t make a bottomsheet go all the way up screen

I’m an internship in a company and I’m not receiving all the support I’d like to. I have this FAQ screen with a button that should bring up a bottomsheet so the customer can contact us. The problem is, it goes up like 75% and the sheet then has to be dragged up to the ‘send’ button actually show. I have tried everything for like 6 hours now… messing with the XML and the Kotlin classes. Yep, my code is a mess and I’m lost, please help me. The only “solution” I found was to emulate it in a XL screen.

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.SearchView
        android:id="@+id/search_faq_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerviewFaq"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="45dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.176"
        tools:listitem="@layout/faq_itens_recycler" />

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="0dp"
        android:layout_height="49dp"
        android:layout_marginTop="18dp"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        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/guideline4"
        app:layout_constraintVertical_bias="1.0">


        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/bottomSheet"
            style="@style/Widget.MaterialComponents.BottomSheet.Modal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_peekHeight="2000dp"
            app:cardBackgroundColor="#eee"
            app:cardCornerRadius="0dp"
            app:cardElevation="8dp"
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">


        </androidx.coordinatorlayout.widget.CoordinatorLayout>

        <FrameLayout
            android:id="@+id/sheet"
            android:layout_width="wrap_content"
            android:layout_height="49dp"
            app:behavior_peekHeight="1dp"
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"

            />

        <TextView
            android:id="@+id/textView"
            android:layout_width="168dp"
            android:layout_height="48dp"
            android:layout_marginStart="2dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="0dp"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="@string/txt_faq"
            android:textColor="#ffffff" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_contato"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="190dp"
            android:layout_marginBottom="0dp"
            android:text="@string/txt_btn_contato_faq" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent=".86" />


</androidx.constraintlayout.widget.ConstraintLayout>
    
class Faq : AnielFragment() {

    private var searchView: SearchView? = null
    private var recycle: RecyclerView? = null
    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
        inflater.inflate(R.menu.menu_faq_perguntas_e_respostas, menu)
        val searchManager = requireContext().getSystemService(Context.SEARCH_SERVICE) as SearchManager
        searchView = menu.findItem(R.id.search_menu_faq_perguntas_e_respostas).actionView as SearchView
        searchView!!.setSearchableInfo(searchManager.getSearchableInfo(requireActivity().componentName))
        searchView!!.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
            override fun onQueryTextSubmit(query: String): Boolean {
                return false
            }

            override fun onQueryTextChange(newText: String): Boolean {
                activity!!.runOnUiThread {
                    recycle!!.adapter = FaqAdapter(FaqItens.filter(newText), context)
                    recycle!!.layoutManager = LinearLayoutManager(
                        context, LinearLayoutManager.VERTICAL, false
                    )
                }
                return false
            }
        })
        super.onCreateOptionsMenu(menu, inflater)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        return super.onOptionsItemSelected(item)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Infla o layout generico que tem o recyclerview
        val rootView = inflater.inflate(R.layout.faq_recyclerview, container, false)
        recycle = rootView.findViewById(R.id.recyclerviewFaq)
        val btn_contato = rootView.findViewById<Button>(R.id.btn_contato)
        btn_contato.setOnClickListener {
            val bottomSheetFaq = FaqViewModel()
            bottomSheetFaq.show(childFragmentManager, "BUSCAMATERIALBOTTOM")
        }
        setHasOptionsMenu(true)
        // M├ętodo que adiciona um titulo na ActionBar da activity
        requireActivity().title = "Perguntas Frequentes"
        return rootView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // searchView = getView().findViewById(R.id.search_faq_recyclerview);
        AnielProgressDialog(activity).setOnProcess(object : onProcess() {
            @Throws(Exception::class)
            override fun onStartProcess(o: Any?): Any? {
                return FaqItens.valores()
            }

            @Throws(Exception::class)
            override fun onFinishProcess(result: Any?): Any? {
                val itens = result as List<FaqItens>?
                recycle!!.adapter = FaqAdapter(itens, context)
                recycle!!.layoutManager =
                    LinearLayoutManager(context, RecyclerView.VERTICAL, false)
                return null
            }

            override fun onFail(e: Exception) {}
        }).show()
    }
}


class FaqViewModel : BottomSheetDialogFragment() {

    @SuppressLint("RestrictedApi")
    override fun setupDialog(dialog: Dialog, style: Int) {
        super.setupDialog(dialog, style)
        val contentView = View.inflate(context, R.layout.faq_contato, null)
        dialog!!.setContentView(contentView)
        //  contentView.getLayoutParams().height = 900
        val txtNomeEmpresa = dialog.findViewById<TextView>(R.id.faq_mais_informacoes_nome_empresa)
        val txtMensagemSuporte = dialog.findViewById<TextView>(R.id.faq_mais_informacoes_mensagem_informacoes)
        AnielProgressDialog(activity).setOnProcess(object : onProcess() {
                @Throws(Exception::class)
                override fun onStartProcess(o: Any?): Any? {
                    // int token =  new Server<Response>(getContext()).getToken();
                    val empresa = Server<Response<*>>(
                        context
                    ).descricao
                    val mensagemSuporte = Server<Response<*>>(
                        context
                    ).mensagemSuporte
                    //List<Aplicativo> aa = PortalSinapse.obterEmpresa(getContext(),token);
                    txtNomeEmpresa.text = empresa
                    txtMensagemSuporte.text = mensagemSuporte
                    return null
                }

                @Throws(Exception::class)
                override fun onFinishProcess(result: Any?): Any? {
                    return super.onFinishProcess(result)
                }

                override fun onFail(e: Exception) {}
        }).show()
    }
}

Advertisement

Answer

In my case i was also having same problem like yours, i fixed it by following code let me know if it fix yours, it place the fragment to fullscreen. Add this in your FaqViewModel Class

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = BottomSheetDialog(requireContext(), theme)
        dialog.setOnShowListener {

            val bottomSheetDialog = it as BottomSheetDialog
            val parentLayout =
                bottomSheetDialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
            parentLayout?.let { it ->
                val behaviour = BottomSheetBehavior.from(it)
                behaviour.isDraggable = false
                setupFullHeight(it)
                behaviour.state = BottomSheetBehavior.STATE_EXPANDED
            }
        }
        return dialog
    }

    private fun setupFullHeight(bottomSheet: View) {
        val layoutParams = bottomSheet.layoutParams
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT
        bottomSheet.layoutParams = layoutParams
    }
10 People found this is helpful
Advertisement