I am loading a certain web page in my android application using a webview and I want to disable the android keyboard for some screens and enable the android keyboard for some screens. So I tried implementing several approaches non of them work. When I set all the properties to support the keyboard enable and then try to disable it, it still pops out. These are the things I have done,
class SampleWebview(context: Context, attrs: AttributeSet): WebView(context, attrs) {
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
return null
}
override fun onCheckIsTextEditor(): Boolean {
println("onCheckIsTextEditor")
return false
}
}
I tried setting the onCheckIsTextEditor to false but it still keeps popping out. Please note that the above created SampleWebview was used in the layout file and references inside the Main Activity as well. Then I tried this,
wb.webViewClient = object: WebViewClient(){
override fun onPageFinished(view: WebView?, url: String?) {
viewModel.onPageFinishedLoading()
}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
if(url?.contains("/hide", true) == false){
wb.isFocusable = true
wb.isFocusableInTouchMode = true
pt.descendantFocusability = ViewGroup.FOCUS_BEFORE_DESCENDANTS
} else {
wb.isFocusable = false
wb.isFocusableInTouchMode = false
pt.descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
}
}
}
But this doesn't work as well. But if i set the
wb.isFocusable = false
wb.isFocusableInTouchMode = false
pt.descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
and doesn't change them then the soft keyboard is disabled for the entire application (which is great), but I need the soft keyboard to be enabled for some screens in the webview. How to achieve this? I have been trying different solutions for hours now, and yet no exact solution. Any guidance for this is much appreciated.
To sum up things again, what i need is to enable the android soft keyboard for some screens in the website and to disable it on some screens in the website which is displayed inside the Webview.
Let's look at this at another approach. You can hide the keyboard by making the keyboard lose focus. You can also use this as an example to you code. It uses a button and an edit text.
Using the
input managerwill cause the keyboard to lose focus and hide. You can also use this in the main portion to where you tap anywhere on the screen and the keyboard will hide.This is a method of hiding (not disabling) the keyboard.