Android: Keyboard overlaps with the EditText (with printscreens)
I have tried your XML and yes you are right the problem occur.
To solve the problem I have written this line in my MainActivity.java hope this help to you,And put the layout XML in ScrollView.
Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
final EditText time = (EditText)findViewById(R.id.timeET);
time.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
final EditText date = (EditText)findViewById(R.id.dateET);
date.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
time.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
}
And The XML is Like,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:id="@+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="1">
---
---
---
</ScrollView>
</LinearLayout>
Keyboard overlapping EditText on click
What about setting RESIZE
instead of PAN
? You will be able to keep your EditText
above the SoftKeyboard
. Try as follows:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
However, instead of doing this at runtime, you can set it in the manifest
as an Activity
(parent) attribute. This will also be handled in your fragment (child):
<activity
android:name=".NameActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
Then, as you can see, the EditText
is above the SoftKeyboard, but from your layout, you have a TextView
with android:layout_alignParentBottom="true"
attribute which will overlap the EditText
:
To prevent this behaviour, just set the ScrollView
above the last TextView
as follows:
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ret"> <!-- instead of "footer" -->
And you will get the following result:
adjustPan not preventing keyboard from covering EditText
After doing a lot of searching apparently it's what I'm calling a bug. If you use the fullscreen tag (to remove the status bar from the activity) you can't use "adjustResize" without wrapping the activity in a ScrollView. Unfortunately for me I'm using a ListView which would create yet another problem. I'm sick of messing with it and will probably just abandon the fullscreen on that activity.
Soft keyboard covers an EditText in a PopupWindow
For anyone stumbling upon this in the future, I ended up just using a Dialog instead of a PopupWindow, and panning to keep the EditText in view works fine on 2.2 with a Dialog.
Android: Resize only parts of view with soft keyboard on screen
The full solution involves a few key points
- Use
RelativeLayout
, so thatViews
can be setup to overlap one another - Align the
EditText
with the bottom of theWindows
usingandroid:layout_alignParentBottom="true"
- Use
android:windowSoftInputMode="adjustResize"
in your manifest, so that the bottom of theWindow
changes when the keyboard pops up (as you mentioned) - Put the
ImageView
inside aScrollView
so that theImageView
can be larger than theWindow
, and disable scrolling on theScrollView
by usingScrollView#setEnabled(false)
Here is the layout file
<RelativeLayout
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="com.so3.MainActivity">
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/stickfigures"/>
</ScrollView>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/holo_blue_bright"
android:text="Please enter text"
android:textSize="40sp"
android:gravity="center_horizontal"/>
</RelativeLayout>
Here is my Activity
package com.so3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScrollView sv = (ScrollView)findViewById(R.id.scroll);
sv.setEnabled(false);
}
}
My AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.so3" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.so3.MainActivity"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Screen shots of my solution
Related Topics
How to Embed a Youtube Clip in a Webview on Android
Disabling Android's Chrome Pull-Down-To-Refresh Feature
Play Youtube HTML5 Embedded Video in Android Webview
Android Add Image to Webview from a Drawable
Input Has Different Style on Focus
Getting Net::Err_Unknown_Url_Scheme While Calling Telephone Number from HTML Page in Android
Disable Android Browser's Input Overlays
Android: HTML in Textview with Link Clickable
Call an Activity Method from a Broadcastreceiver Class
Android Browser Ignores Responsive Web Design
What Is The Easiest Way to Use Svg Images in Android
Why Bitmap to Base64 String Showing Black Background on Webview in Android
Shared Preferences Reset Data When App Is Force Closed or Device Is Restarted
Activity.Finish() Called But Activity Stays Loaded in Memory
CSS Overflow and Absolute Positioning Issue on Android Browser
Using Multiple Text Colors in Android's Textview [ HTML.Fromhtml() ]