Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android keyboard hides input in web view

In an Android webview, when a text/password field is touched, the keyboard appears but covers the field, forcing the user to scroll to see what they are typing.

Is there a way to solve this issue or a way to have an auto-focus in web view ? (as seen in iOS).

Manifest

<?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>

Layout

<?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>

I also paste styles and colors here:

colors.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>

styles.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>
like image 459
Stefano Avatar asked Dec 16 '19 12:12

Stefano


3 Answers

Try adding the following property:

android:fitsSystemWindows="true"

in the root LinearLayout of the .xml layout.

like image 135
animeshk Avatar answered Sep 27 '22 18:09

animeshk


You might want to check this article: https://developer.android.com/training/keyboard-input/visibility

Maybe this will help you.

android:windowSoftInputMode="adjustResize"
like image 21
Sebastian M Avatar answered Sep 27 '22 19:09

Sebastian M


Android keyboard hides when the app use full screen mode.

This issue can be resolved if you use

<item name="android:windowFullscreen">false</item> in your styles.

then use <activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize">

in your manifest.

like image 27
Nawin Avatar answered Sep 27 '22 17:09

Nawin