android - Android 键盘在 Web 视图中隐藏输入
问题描述
在 Android webview 中,当触摸文本/密码字段时,键盘会出现但会覆盖该字段,迫使用户滚动查看他们正在输入的内容。
有没有办法解决这个问题或在网页视图中自动对焦?(如在 iOS 中所见)。
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dedalos.amb">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:windowSoftInputMode="adjustPan"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen" android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>
</manifest>
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/splash_background"
tools:context=".MainActivity">
<WebView
android:id="@+id/ambWebViewLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/splash_background" />
</LinearLayout>
我还在这里粘贴样式和颜色:
颜色.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="splash_background">#e11020</color>
</resources>
样式.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#e11020</item>
<item name="colorPrimaryDark">#e11020</item>
<item name="colorAccent">#e11020</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<!-- SplashTheme -->
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash_theme</item>
</style>
</resources>
解决方案
尝试添加以下属性:
android:fitsSystemWindows="true"
在 .xml 布局的根 LinearLayout 中。
推荐阅读
- javascript - 如何在php中只允许png文件类型
- javascript - 如何在 C# 代码块中使用 javascript 变量
- elasticsearch - 如何在 Elasticsearch 7 NEST 7 中设置“max_result_window”
- c++ - 传递 unique_ptr 时调试和发布配置的移动不一致?
- javascript - 如何使用 Javascript 格式化数字?
- javascript - JavaScript 对象动态检索值
- php - 自定义帖子类型内容未显示在单页上
- datetime - 如何将儒略日期转换为雪花中的时间戳
- xfs - 我如何知道自动提款机交易是成功还是失败?
- docker - Light4J Oauth2 docker-compose 错误提示找不到指定的 Dockerfile