最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Android Button text is cut off in BottomSheetDialogFragment - Stack Overflow

programmeradmin4浏览0评论

My Button text is cut off althought layout preview shows it correct way. When I run it on my real phone it is cut off with ... instead of going to new line. I am attaching screenshots:

what I want:

what I have:

Here is my code:

FragmentDiscover.kt

val dialog = BottomSheetDialogFragmentNew.newInstance()
dialog.show(parentFragmentManager, dialog.javaClass.simpleName)

BottomSheetDialogFragmentNew.kt

class BottomSheetDialogFragmentNew : BottomSheetDialogFragment() {

    private var binding: BottomSheetDialogAddNewBinding? = null

    companion object {
        fun newInstance(): BottomSheetDialogFragmentNew {
            val fragment = BottomSheetDialogFragmentNew()
            return fragment
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        binding = BottomSheetDialogAddNewBinding.inflate(layoutInflater)
        return binding!!.root
    }


    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return super.onCreateDialog(savedInstanceState).apply {
            setCancelable(true)
            setCanceledOnTouchOutside(true)
            setOnKeyListener { _: DialogInterface, keyCode: Int, keyEvent: KeyEvent ->
                if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
                    dismiss()
                }
                return@setOnKeyListener false
            }
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        binding!!.ivAnswerToSomeUsersRequestsInfo.setOnClickListener({
            val bottomSheetDialogLayout = layoutInflater.inflate(R.layout.bottom_sheet_dialog_why_to_answer_users_questions, null)
            val dialog = BottomSheetDialog(requireContext())
            dialog.setContentView(bottomSheetDialogLayout)
            dialog.setCanceledOnTouchOutside(true)
            bottomSheetDialogLayout.findViewById<Button>(R.id.b_ok).setOnClickListener {
                dialog.dismiss()
            }
            dialog.show()
        })


        val bottomSheet: FrameLayout = dialog?.findViewById(com.google.android.material.R.id.design_bottom_sheet)!!

        bottomSheet.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT

    }

    override fun onPause() {
        super.onPause()
        dismiss()
    }

    override fun onCancel(dialog: DialogInterface) {
        super.onCancel(dialog)
        dismiss()
    }
}

bottom_sheet_dialog_add_new.xml

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tv_answer_to_request"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:text="Feeling strong today? 
发布评论

评论列表(0)

  1. 暂无评论