Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Keyboard overlaps with the EditText (with printscreens)

Tags:

android

I have an EditText (that the user can type numbers in), so when the user clicks on the EditText text box a keyboard with numbers is opened.

This is how it looks when the text box is clicked

as you can see the keyboard hides a small part of the text box.

But when I press a key, for example, 0, it looks ok. This is how it looks after after clicking 0

Is there anything I can do (besides putting the EditText higher) so it will looks like it does in the second picture?

Edit: the .xml code:

 <?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" android:weightSum="1">
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
    <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
        <android.widget.CheckedTextView android:id="@+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="@string/toString"></android.widget.CheckedTextView>
        <AutoCompleteTextView android:layout_height="wrap_content" android:id="@+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="@string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
            <requestFocus></requestFocus>
        </AutoCompleteTextView>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2">
            <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="@string/contactsString" android:textSize="17sp" android:id="@+id/contactsButton"></Button>
            <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/groupsString" android:layout_width="fill_parent" android:id="@+id/groupsButton" android:textSize="17sp"></Button>
            <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/favouritesString" android:layout_width="fill_parent" android:id="@+id/button3" android:textSize="17sp"></Button>
        </LinearLayout>
        <TextView android:id="@+id/textView1" android:text="@string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
        <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
        <TextView android:id="@+id/textView2" android:text="@string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
        <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner"></Spinner>
        <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="fill_parent">
            <ImageView android:src="@drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_weight="0.1"></ImageView>
            <EditText android:layout_height="wrap_content" android:id="@+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
            <ImageView android:src="@drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:layout_weight="0.1"></ImageView>
            <EditText android:layout_height="wrap_content" android:id="@+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
        </LinearLayout>
        <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
                <Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="@string/button_ok" android:layout_width="fill_parent" android:id="@+id/button4" android:textSize="17sp"></Button>
                <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/button5" android:layout_weight="0.5" android:text="@string/button_cancel" android:textSize="17sp"></Button>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

</LinearLayout>
like image 264
Belgi Avatar asked Nov 03 '11 19:11

Belgi


People also ask

How do I hide the soft keyboard on Android after clicking outside EditText?

and put the following code in the onTouch method. InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);

How do I scroll up layout when clicking on EditText?

try this android:windowSoftInputMode="adjustResize" in your activity in manifest file.


2 Answers

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> 
like image 123
MKJParekh Avatar answered Oct 10 '22 03:10

MKJParekh


Change to ScrollView in this way:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1" >
        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <LinearLayout
                android:layout_width="wrap_content"
                android:orientation="vertical"
                android:layout_height="wrap_content"
                android:id="@+id/linearLayout1"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true" >
                <android.widget.CheckedTextView
                    android:id="@+id/checkedTextView1"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:textSize="17sp"
                    android:text="@string/toString" />
                <AutoCompleteTextView
                    android:layout_height="wrap_content"
                    android:id="@+id/autoCompleteTextView1"
                    android:layout_width="fill_parent"
                    android:text="@string/emptyString"
                    android:textSize="17sp"
                    android:gravity="top|left"
                    android:minHeight="62dp" >
                    <requestFocus></requestFocus>
                </AutoCompleteTextView>
                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/linearLayout2" >
                    <Button
                        android:layout_height="wrap_content"
                        android:layout_width="fill_parent"
                        android:layout_weight="0.33333333333"
                        android:text="@string/contactsString"
                        android:textSize="17sp"
                        android:id="@+id/contactsButton" />
                    <Button
                        android:layout_weight="0.33333333333"
                        android:layout_height="wrap_content"
                        android:text="@string/groupsString"
                        android:layout_width="fill_parent"
                        android:id="@+id/groupsButton"
                        android:textSize="17sp" />
                    <Button
                        android:layout_weight="0.33333333333"
                        android:layout_height="wrap_content"
                        android:text="@string/favouritesString"
                        android:layout_width="fill_parent"
                        android:id="@+id/button3"
                        android:textSize="17sp" />
                </LinearLayout>
                <TextView
                    android:id="@+id/textView1"
                    android:text="@string/messageString"
                    android:layout_height="wrap_content"
                    android:textSize="17sp"
                    android:layout_width="fill_parent" />
                <EditText
                    android:layout_height="wrap_content"
                    android:id="@+id/editText1"
                    android:layout_width="fill_parent"
                    android:gravity="top|left"
                    android:minHeight="105dp" />
                <TextView
                    android:id="@+id/textView2"
                    android:text="@string/repetition"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:textSize="17sp" />
                <Spinner
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/spinner" />
                <LinearLayout
                    android:layout_height="wrap_content"
                    android:id="@+id/linearLayout3"
                    android:layout_width="fill_parent" >
                    <ImageView
                        android:src="@drawable/button_time"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/imageView1"
                        android:layout_weight="0.1" />
                    <EditText
                        android:layout_height="wrap_content"
                        android:id="@+id/timeET"
                        android:inputType="number"
                        android:layout_width="wrap_content"
                        android:layout_weight="0.4" />
                    <ImageView
                        android:src="@drawable/button_date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/imageView2"
                        android:layout_weight="0.1" />
                    <EditText
                        android:layout_height="wrap_content"
                        android:id="@+id/dateET"
                        android:inputType="number"
                        android:layout_width="wrap_content"
                        android:layout_weight="0.4"
                        android:layout_marginRight="3dp" />
                </LinearLayout>
                <RelativeLayout
                    android:id="@+id/relativeLayout2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/linearLayout4"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentLeft="true" >
                        <Button
                            android:layout_weight="0.5"
                            android:layout_height="wrap_content"
                            android:text="@string/button_ok"
                            android:layout_width="fill_parent"
                            android:id="@+id/button4"
                            android:textSize="17sp" />
                        <Button
                            android:layout_height="wrap_content"
                            android:layout_width="fill_parent"
                            android:id="@+id/button5"
                            android:layout_weight="0.5"
                            android:text="@string/button_cancel"
                            android:textSize="17sp" />
                    </LinearLayout>
                </RelativeLayout>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>
like image 28
Sherif elKhatib Avatar answered Oct 10 '22 01:10

Sherif elKhatib