EditText not showing with keyboard open

I have a fullscreen view with a fullscreen ImageView in the background. I have an EditText located in the middle of the screen using gravity:center. When the keyboard opens, I want the EditText to move up, as shown in the figure below, so that the entire EditText is always visible. I tried to use android:windowSoftInputMode="stateVisible|adjustResize", however, the problem with this is that my image in the background is also changing, which is undesirable. In addition, since gravity is set to the center, this leads to a gap between the EditText and the keyboard, so that it is still in the center. I tried using scrollView, but I did not know how to get the position at which the keyboard ends so that I can move my EditText to that position. I also triedadjustPanhowever this did not have any effect since the EditText has a 200dpheight value and the gravity value is set to the center, so the user always starts typing in the middle of the EditText that is still displayed.

XML

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout
    android:id="@+id/camera_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    android:id="@+id/picturedisplay"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_gravity="center"
        android:layout_height="200dp"
        android:weightSum="100"
        android:visibility="gone"
        android:id="@+id/pic_layout"
        android:orientation="vertical"
        android:background="#9945D199"
        >
        <EditText
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:hint="Enter text here..."
            android:textColor="#FFFFFF"
            android:maxLength="250"
            android:gravity="center"
            android:imeOptions="flagNoExtractUi"
            android:id="@+id/pic_textbox"
            android:layout_weight="90"/>
        <TextView
            android:layout_width="40dp"
            android:layout_height="0px"
            android:text="200"
            android:textColor="#FFFFFF"
            android:textStyle="bold"
            android:gravity="center_horizontal"
            android:layout_weight="10"
            android:id="@+id/char_rem_view"
            android:layout_gravity="end"/>
    </LinearLayout>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imgClose"
    android:layout_gravity="right|bottom"
    android:text="Flip Cam"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/snap"
    android:text="Capture"
    android:layout_gravity="center|bottom"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Flash"
    android:visibility="visible"
    android:id="@+id/imgOpen"
    android:layout_gravity="left|bottom"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/addText"
    android:layout_gravity="right|bottom"
    android:text="Add Text"
    android:visibility="gone"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/addPic"
    android:text="Add Pic"
    android:visibility="gone"
    android:layout_gravity="center|bottom"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Delete"
    android:id="@+id/delete"
    android:visibility="gone"
    android:layout_gravity="left|bottom"
    android:padding="20dp"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save"
    android:id="@+id/save_photo"
    android:visibility="gone"
    android:layout_gravity="right|top"
    android:padding="20dp"/>

enter image description here

+4
source share
2 answers

add this to your EditTextxml,

android:imeOptions="flagNoExtractUi"

I am not sure if this method does not meet your needs, hope you can help :)

0
source

Open your menifest.xml, find your activity and add this single line

<activity android:windowSoftInputMode="adjustResize" />

or

<activity android:windowSoftInputMode="adjustPan" />

activity tag should look lower

<activity
    android:name="com.my.MainActivity" //Change this to your.package.ActivityName
    android:screenOrientation="portrait"
    android:label="@string/title_activity_main"
    android:windowSoftInputMode="adjustPan" >
</activity>

or

<activity
    android:name="com.my.MainActivity"  //Change this to your.package.ActivityName
    android:screenOrientation="portrait"
    android:label="@string/title_activity_main"
    android:windowSoftInputMode="adjustResize" >
</activity>

Update 1

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout
    android:id="@+id/camera_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

<ImageView
    android:id="@+id/picturedisplay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone" />

<LinearLayout
    android:id="@+id/pic_layout"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:background="#9945D199"
    android:gravity="center"
    android:orientation="vertical"
    android:visibility="visible">

    <EditText
        android:id="@+id/pic_textbox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center"
        android:hint="Enter text here..."
        android:maxLength="250"
        android:maxLines="6"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/char_rem_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:gravity="center_horizontal"
        android:padding="5dp"
        android:text="200"
        android:textColor="#FFFFFF"
        android:textStyle="bold" />
</LinearLayout>

<Button
    android:id="@+id/imgClose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    android:padding="20dp"
    android:text="Flip Cam" />

<Button
    android:id="@+id/snap"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|bottom"
    android:padding="20dp"
    android:text="Capture" />

<Button
    android:id="@+id/imgOpen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left|bottom"
    android:padding="20dp"
    android:text="Flash"
    android:visibility="visible" />

<Button
    android:id="@+id/addText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    android:padding="20dp"
    android:text="Add Text"
    android:visibility="gone" />

<Button
    android:id="@+id/addPic"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|bottom"
    android:padding="20dp"
    android:text="Add Pic"
    android:visibility="gone" />

<Button
    android:id="@+id/delete"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left|bottom"
    android:padding="20dp"
    android:text="Delete"
    android:visibility="gone" />

<Button
    android:id="@+id/save_photo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|top"
    android:padding="20dp"
    android:text="Save"
    android:visibility="gone" />

</FrameLayout>
-1
source

Source: https://habr.com/ru/post/1629487/


All Articles