Instead of the classic keyboard, when I click to log in to the webview, I need to open the soft keyboard. I searched the internet everywhere. tried all the examples and nothing. The standard always opens. Over the phone, android 11 ,. Made virtual 8 and 9. Same. How can only be open a soft keyboard
CodePudding user response:
Have you tried those attributes in your XML Parent rootView?
android:focusable="true"
android:focusableInTouchMode="true"
CodePudding user response:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@ id/web"
android:layout_width="409dp"
android:layout_height="729dp"
android:imeOptions="actionDone"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
>
</WebView>
</androidx.constraintlayout.widget.ConstraintLayout>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Web"
android:usesCleartextTraffic="true"
>
<activity
android:name=".MainActivity"
android:exported="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val webview = findViewById<WebView>(R.id.web)
webview.settings.setJavaScriptEnabled(true)
webview.loadUrl("https://www.google.com")
}
fun showSoftKeyboard(view: View) {
if (view.requestFocus()) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
}
I tried, simply, to try.
the same