【问题标题】:Kotlin:show soft keyboard in webviewKotlin:在 webview 中显示软键盘
【发布时间】:2021-12-31 12:40:19
【问题描述】:

代替经典键盘,当我点击登录webview时,需要打开软键盘。 我到处搜索互联网。尝试了所有示例,但没有。标准总是打开的。 通过电话,android 11,。虚拟 8 和 9。相同。 怎么只能打开软键盘

【问题讨论】:

  • “软键盘”是指屏幕上的键盘,而不是硬件键盘(带有物理按钮)。如果用户安装了多个键盘,弹出哪一个取决于他们的系统设置

标签: android kotlin webview android-softkeyboard


【解决方案1】:

您是否在 XML Parent rootView 中尝试过这些属性?

android:focusable="true"
android:focusableInTouchMode="true"

【讨论】:

    【解决方案2】:
        <?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)
        }
    }
    

    我试过了,只是想试试。
    一样的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2013-12-16
      相关资源
      最近更新 更多