Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why keyboard is overlap on the AutoCompleteTextView when inside ScrollView

I have a simple android layout and code, but the keyboard always overlap my AutoCompleteTextView when I click it. Note : The AutoCompleteTextView when inside ScrollView. Note : platform is 6.0.1

package com.example.jason_wu.search;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;

public class Main2Activity extends AppCompatActivity {
    private AutoCompleteTextView mAtv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        mAtv = (AutoCompleteTextView) findViewById(R.id.location_auto_complete);
        //issue 1
        //mAtv.setBackground(getDrawable(R.drawable.search_input_focus));
        //issue 2
        mAtv.setHeight(300);
    }
}

and my AndroidManifest.xml here:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jason_wu.search">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.example.jason_wu.search.Main2Activity"
        android:windowSoftInputMode="adjustPan"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>


Layout.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView" >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="800dp"
                android:text="Large Text"
                android:id="@+id/textView"/>

            <AutoCompleteTextView
                android:id="@+id/location_auto_complete"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/textView"
                android:background="@color/transparent"
                android:dropDownAnchor="@+id/location_auto_complete"
                android:dropDownHeight="wrap_content"
                android:dropDownVerticalOffset="1dip"
                android:fontFamily="sans-serif-light"
                android:hint="@string/new_notification_location_hint"
                android:imeOptions="actionSearch"
                android:inputType="textUri"
                android:dropDownSelector="@color/location_bg_select"
                android:popupBackground="@color/location_bg_notselect"
                android:singleLine="true"
                android:textColor="#FFFFFF"
                android:alpha="0.2"
                android:textColorHint="#999999"
                android:textCursorDrawable="@null"
                android:textSize="15sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:id="@+id/textView2"
                android:layout_below="@+id/location_auto_complete" />

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

See issue 2

like image 941
Chun-Shen Wu Avatar asked Jan 12 '16 06:01

Chun-Shen Wu


People also ask

What is auto complete text view?

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

What is windowSoftInputMode?

Android has the so-called Input Method Framework to support different input methods, e.g. keyboard, soft-keyboard, handwriting etc. If the soft-keyboard is used it is diplayed at the bottom of the screen once the user select an text view to edit it.


1 Answers

Try limiting the dropdown items to show

One way is you can Limit the dropdown items to show. But there's no such proper way of it to show number of maximumSuggestions option, But the trick you can apply is Get the height of one of the rows and multiply it (number of rows to show) times and use setDropDownHeight() to set its height.

There is a method setDropDownHeight of AutoCompleteTextView class. You can see them and use.

If you are confused or not sure of height of suggestions items you can customize this. Have a look how to set custom height.

like image 195
Shree Krishna Avatar answered Oct 21 '22 02:10

Shree Krishna