键盘未在弹出窗口中显示

问题描述

我只是无法自定义键盘显示。如果文本输入元素位于主布局上,则在单击文本表单时,将显示键盘。但是我有一个输入表单,其布局与附件中的照片一样,处于单独的布局,并且该表单显示在主表单的顶部。弹出窗口。并且尝试以这种形式输入文本时,不会出现键盘

class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        window.decorView.apply {
            systemUIVisibility = View.SYstem_UI_FLAG_HIDE_NAVIGATION or View.SYstem_UI_FLAG_FULLSCREEN
        }
        setContentView(R.layout.activity_main)
        //label_sign.text = "SIGN IN".toString()


        ImageButton.setonClickListener {
            Thread {
                ImageButton.setimageResource(R.drawable.call_click)
                Thread.sleep(300)
                ImageButton.setimageResource(R.drawable.call)
            }.start()

            val window = PopupWindow(this)
            val view = layoutInflater.inflate(R.layout.layout_popup,null)

            window.contentView = view
            val call_fon = view.findViewById<ImageView>(R.id.call_fon)

            call_fon.setonClickListener{
                window.dismiss()
            }
            window.showAtLocation(ImageButton,Gravity.CENTER,0)

        }
    }
}

enter image description here

enter image description here

解决方法

似乎是聚焦视图的问题,我正在使用这段代码来强制softKeyboard显示在Activity中:


    fun showSoftKeyboard(activity: Activity?) {
        activity?.currentFocus?.run {
            val imm = (BaseApplication.application.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager)
            imm.showSoftInput(this,InputMethodManager.SHOW_FORCED)
        }
    }

如果这样做没有帮助,请考虑粘贴简化的layout_popup.xml