I have seen these answers.
My androidManifest.xml file contains: android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" >
In one of my fragments, i need to call the soft keyboard. As soon as I call the soft keyboard, the action bar appears as well, and is never hidden after that. In that fragment, I have:
view.setOnClickListener {
val imm = context?.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
(activity as AppCompatActivity).supportActionBar?.hide()
}
I expect this to hide the keyboard if a part of the fragment besides the input area was tapped (which it does), and also hide the action bar (it does not).
In this fragment, there is a button. On click, a new fragment is loaded. In that newly Loaded fragment's onCreateView I have:
(activity as AppCompatActivity).supportActionBar?.hide()
In the same fragment's onResume I have:
override fun onResume() {
super.onResume()
(activity as AppCompatActivity).actionBar?.hide()
(activity as AppCompatActivity).supportActionBar?.hide()
}
But the action bar persists.
My android SDKs are as follows:
ANDROID_MIN_SDK_VERSION=23
ANDROID_TARGET_SDK_VERSION=33
ANDROID_COMPILE_SDK_VERSION=33
KOTLIN_VERSION = 1.6.10
Question:
How can I force the action bar to stay hidden, even if the Soft keyboard is called?Thank you
I believe this method will solve your problem. It basically listens the keyboard visibility and hides action bar if its visible as you see below. Call it on your activity