How to turn off keyboard icon at TimePicker?

后端 未结 5 1373
遥遥无期
遥遥无期 2021-01-07 00:56

I have a timepicker, everything works well but the problem is that I can\'t make it look like designer wants. For now it looks like this:

I need to hide this keybo

5条回答
  •  無奈伤痛
    2021-01-07 01:28

    Okay this is my solution. After inspecting the Layout I found that the keyboard is AppCompatImageButton. So you just do a recursion over the TimePicker which is a Viewgroup. So you can call it for example like this:

    private fun initTimePicker() {
        timePicker.setIs24HourView(true)
        setImageButtonToGone(timePicker)
    }
    
    private fun setImageButtonToGone(viewGroup: ViewGroup) {
        for (i in 0 until viewGroup.childCount) {
            val child = viewGroup.getChildAt(i)
            if (child is LinearLayout) {
                setImageButtonToGone(child)
            } else if (child is AppCompatImageButton) {
                child.visibility = View.GONE
            }
        }
    }
    

    And you will get the desired layout.

    WARNING!!! This depends heavely that the keyboard button is the only AppCompatImageButton if they change the XML of TimePicker this will not work properly anymore.

提交回复
热议问题