首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Kotlin:在webview中显示软键盘

Kotlin:在webview中显示软键盘
EN

Stack Overflow用户
提问于 2021-12-31 12:40:19
回答 2查看 295关注 0票数 0

而不是传统的键盘,当我点击登录到webview时,我需要打开软键盘。我到处搜索互联网。尝试了所有的例子却什么也没有。标准总是开放的。在电话里,android 11。虚拟8和9一样。如何才能打开软键盘

EN

回答 2

Stack Overflow用户

发布于 2021-12-31 14:08:55

您在XML父rootView中尝试过这些属性吗?

代码语言:javascript
运行
复制
android:focusable="true"
android:focusableInTouchMode="true"
票数 0
EN

Stack Overflow用户

发布于 2022-01-03 08:31:56

代码语言:javascript
运行
复制
    <?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)
    }
}

我试过,很简单,只是想试一试。

同样的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70542442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档