getSystemServices is undefined when called in a Fragment?

前端 未结 7 1826
醉酒成梦
醉酒成梦 2020-12-08 18:59

I want TextViews to display the sensors readings in a Fragment. When trying to initialize the SensorManager the getSystemService

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 19:15

    For kotlin this is what worked for me.

    private fun hideKeyboard() {
            val inputManager = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            if (inputManager.isAcceptingText) {
                inputManager.hideSoftInputFromWindow(activity?.currentFocus?.windowToken, 0)
            }
        }
    

提交回复
热议问题