Why keyboard is overlap on the AutoCompleteTextView when inside ScrollView - android

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

try this attribute to the activity in the AndroidManifest.xml
android:windowSoftInputMode="stateHidden|adjustPan"
it should look something like this.
<activity
android:name="com.myexample.TestActivity"
android:label="#string/login_screen"
android:screenOrientation="portrait" // well you can change the orientation if you want
android:windowSoftInputMode="stateHidden|adjustPan" />
the attribute you want to play with is this windowSoftInputMode try different values as you may require different output after certain time.
adjustPan
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
adjustResize
The activity's main window is always resized to make room for the soft keyboard on screen.
stateHidden
The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
you can find more details on activity-element documentation
Update
I have written something that might help you, layout is available on the 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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activities.list.first.TestLayoutActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<AutoCompleteTextView
android:id="#+id/TestLayoutActivity_autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:completionThreshold="1"
android:drawableLeft="#android:drawable/ic_menu_search"
android:text="" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
AndroidManifest.xml
<activity
android:name="activities.list.first.TestLayoutActivity"
android:label="#string/title_activity_test_layout"
android:windowSoftInputMode="stateHidden|adjustPan"
/>
Code is on the code
String[] list = {"match1", "match2", "match3",
"match12", "match11", "match8", "match7", "match4",
"match13", "match10", "match9", "match6", "match5",};
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.TestLayoutActivity_autoCompleteTextView);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(getApplicationContext(), R.layout.simple_list_item_1, list);
autoCompleteTextView.setAdapter(adapter);
Before
After
[

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.

The keyboard behavior is that scroll the view to close the bottom of text area.
Finally, we have to use android:gravity="bottom" attribute to solve UI issue, but we need to consider the UX, ex: Hint.
So, The solution is to listen onClick() and For keyboard issue, we have to use dynamic method to set the gravity.

Related

Recycler View background image gets shrink when keyboard popups through editText

I have a recycler-view with a sample background in my activity but I'm stuck in an error. Whenever keyboard popups in the activity, the background of recycler-view gets shrink. How to avoid this thing. Means how to stop it from being shrinking ? Here are the images attached below.
normal Image
shrinked background
XML Code:
<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"
android:background="#drawable/splash_bg"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/editText" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:background="#fff"
android:hint="Your text here"
android:inputType="text"
android:padding="12dp"
android:textSize="24sp" />
</RelativeLayout>
In the tag of the recyclerview container activity declared in manifest add
android:windowSoftInputMode="stateHidden|adjustNothing"
like
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden|adjustNothing" />
add the image to your background of layout, not in recyclerview. And also recyclerview's item should have no background color except its necessary to widgets.
Set attribute android:windowSoftInputMode to be "adjustPan" in your AndroidManifest.xml under your activity:
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="adjustPan" />

Android Studio - Scrollview moves outside the screen on keyboard open

I want to make a chat screen which has an EditText and a Button at the bottom (wrapped in a LinearLayout), and a ScrollView for the messages at the top. The problem is that when the user taps the EditText and the keyboard opens, the ScrollView will go off screen as a result of moving up. I would like to move the Layout (with the EditBox and the Button) above the keyboard and the ScrollView to be resized to fit the screen. The problem is shown on the pictures below:
As you can see, the line that writes "Chat" (left image) has disappeared in the right image.
I use this XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15sp"
android:orientation="vertical"
android:background="#ccdcf7"
tools:context="com.orionz.sockettest.ChatActivity">
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15"
android:isScrollContainer="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/chatBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Chat\n"
android:textColor="#000000"
android:textIsSelectable="true"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="horizontal">
<EditText
android:id="#+id/msgInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:ems="10"
android:hint="Message..."
android:inputType="text" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#drawable/mybutton"
android:padding="5sp"
android:text="Send"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I have seen many answers such as setting the android:windowSoftInputMode but none has worked. I use Android Studio. Any help would be appreciated.
Try to replace the ScrollView with a ListView like this :
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
store all the messages in an ArrayList, and set an adapter to the ListView you made :
ListView listView=(ListView) findViewById(R.id.list_view);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ArrayList);
listView.setAdapter(adapter);
Finally, add a listenner on your Button writing these lines :
EditText editText= (EditText) findViewById(R.id.msgInput);
ArrayList.add(editText.getText().toString());
adapter.notifyDataSetChanged();
Finally, I found what was wrong in my case.
The theme was full screen. In the style of the activity I had this line that caused the problem:
<item name="android:windowFullscreen">true</item>
In the java code, I gave a command to open the keyboard on the start of the activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
which was also part of the problem
After adding the adjustResize property to the activity in the manifest, everything worked fine:
android:windowSoftInputMode="adjustResize"
Wrap Scrollview to the whole layout.
i.e place editText and button inside Scrollview and set scrollView Height to android:layout_height="match_parent"

How to move the layout above of soft keyboard when it is shown

I have a simple layout for my activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonCancel"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="cancel" />
</RelativeLayout>
and when I touch on EditText soft keyboard appears but my button hides beyond the keyboard !
but I wanna the Button move up (above of) the keyboard.
I added this line of code to AndroidManifest but nothing changed.
<activity
android:name=".Activity"
android:windowSoftInputMode="adjustPan|adjustResize">
</activity>
According to the official documentation adjustPan and adjustResize have an opposite behaviour and therefore I don't think they should be used together. Try just android:windowSoftInputMode="adjustResize" , worked for me.

Android: EditText in ScrollView goes of the screen when kayboard appears

I am trying to create a login screen. I have used ScrollView to hold input fields. I have following xml:
<RelativeLayout ... >
<RelativeLayout
android:id="#+id/top_menu" ... >
<ImageButton ... />
<com.neopixl.pixlui.components.textview.TextView... />
</RelativeLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_menu"
android:overScrollMode="always">
<LinearLayout
android:id="#+id/login_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.neopixl.pixlui.components.edittext.EditText
android:id="#+id/user_name_email"
android:layout_width="match_parent"
android:layout_height="#dimen/input_height_size"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/edit_text_strock"
android:hint="#string/user_Name_Email_EditText"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:textColor="#color/White"
android:textColorHint="#color/White"
android:textSize="#dimen/register_input_text_size"
pixlui:typeface="MuseoSans.otf"/>
<com.neopixl.pixlui.components.edittext.EditText.... />
<com.neopixl.pixlui.components.button.Button... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.button.Button... />
</LinearLayout>
</ScrollView>
</RelativeLayout>
You can see full xml here.
When I click on EditText user_name_email, it goes off the screen.
Before click:
After click:
I have tried scrollTo(x, y) and smootScrollTo(x, y) bu they didn't work.
How can I fix it?
UPDATE:
adjustPan works but I want it to work with adjustResize.
Is it possible?
Use the following line in the manifest file, for the activity you need the change.
android:windowSoftInputMode="adjustPan"
Use it as shown below:
<activity
android:name=".ActivityName"
android:label="title_for_activity"
android:windowSoftInputMode="adjustPan" >
</activity>
Hope this helps.
add this to manifest file:
android:windowSoftInputMode="adjustPan"
in the targeted activity tag.

SoftKeyboard hiding EditText

I have a layout that uses an EditText to let users search a database and populate a ListView. The EditText is about 2/3 of the way from the top of the screen (positioned over an ImageView, and followed by some intro text.)
The problem is that the soft keyboard hides the EditText, so the user can't see what he's typing. (I disabled the auto-suggest.)
I've tried LinearLayout, RelativeLayout, paddings, and different alignments/centerings, but I still can't get it to work right. The EditText is either hidden, gets pushed off the top of the screen, or get "squished" and distorted.
Suggestions???
One possible workaround is to move the EditText to the top of the screen. However, this deviates from the graphic design that I was given.
Another possible workaround is for me to make the soft keyboard open in full screen (not sure how, though). This will still hide the EditText, but then I can re-enable the auto-suggestion so the user can see what he's typing... sort of... because he can only see the suggestions for what he's typing.
Here's my latest attempt. See "introFrame".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/titleContainer"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#string/title_string"
android:textSize="15sp" android:textColor="#FFFFFF"
android:textStyle="bold" android:paddingLeft="5dp"
android:layout_height="fill_parent" android:layout_width="wrap_content" />
</LinearLayout>
<FrameLayout
android:id="#+id/introFrame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:src="#drawable/main_search_image"
android:scaleType="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="140dp" >
<LinearLayout android:id="#+id/introSearchContainer"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<EditText android:id="#+id/intro_search_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" Enter keyword "
android:imeOptions="actionGo"
android:inputType="textFilter"
android:maxLines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="#+id/intro_search_button"
android:background="#drawable/custom_button_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="#string/search_intro"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
</FrameLayout>
<LinearLayout android:id="#+id/listContainer"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/itemlist" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:cacheColorHint="#00000000" />
<TextView android:text="No data found" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center"
android:textSize="16sp" android:textColor="#FFFFFF" android:id="#+id/android:empty" />
</LinearLayout>
</LinearLayout>
What you're looking for is the Activity's windowSoftInputMode attribute. You set this in your AndroidManifest.xml file, and give it a value such as:
adjustResize: "The activity's main window is always resized to make room for the soft keyboard on screen."
adjustPan: "The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window."
adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead.
<activity android:windowSoftInputMode="adjustResize" />
or
<activity android:windowSoftInputMode="adjustPan" />
More information is available at the above link.
What has worked for me is to drop my highest-level LinearLayout in a scrollView (the ScrollView can only have one child). This allowed the entire activity/form to scroll up and not clutter the EditText in focus.
First, I set in my activity:
<activity android:windowSoftInputMode="adjustPan" />
Then I did the ScrollView thing I'm talking about:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- STUFF -->
</LinearLayout>
</ScrollView>
just use following in manifest...
<activity
android:windowSoftInputMode="adjustPan">
try giving the edit text a layout_weight (i.e. layout_weight=1) , this may have some other effects on your other layout items that you may have to work through, but this may help it stay visible when soft keyboard pops up

Categories

Resources