[英]Kotlin:show soft keyboard in webview
Instead of the classic keyboard, when I click to log in to the webview, I need to open the soft keyboard.而不是经典键盘,当我点击登录webview时,需要打开软键盘。 I searched the internet everywhere.
我到处搜索互联网。 tried all the examples and nothing.
尝试了所有示例,但没有。 The standard always opens.
标准总是打开的。 Over the phone, android 11,.
通过电话,android 11,。 Made virtual 8 and 9. Same.
虚拟 8 和 9。相同。 How can only be open a soft keyboard
怎么只能开软键盘
Have you tried those attributes in your XML Parent rootView?您是否在 XML Parent rootView 中尝试过这些属性?
android:focusable="true"
android:focusableInTouchMode="true"
<?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相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.