Multiline EditText not scrolling vertically when virtual Keyboard is visible - android

I have EditText that is wrapping content as required; however, when the virtual Keyboard in visible on screen, I am unable to scroll the text vertically to display the lines on top that are hidden from view (e.g., first line when I am typing "android:lines"+1 line). When I hide the keyboard, it starts scrolling normally.
Layout File:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/console_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:id="#+id/repl_container">
<TextView
android:id="#+id/console"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:gravity="left|top"
/>
<ProgressBar
android:id="#+id/progress_running"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:indeterminate="true"
android:visibility="invisible"
style="Widget.ProgressBar.Small"
/>
<EditText
android:id="#+id/code_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textNoSuggestions|textMultiLine"
android:imeOptions="actionNone"
android:imeActionLabel="#string/button_eval"
android:hint="#string/input_code_hint"
android:singleLine="true"
android:gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:scrollHorizontally="false"
android:lines="5"
android:maxLines="100"
/>
<Button
android:id="#+id/button_eval"
android:text="#string/button_evaluate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
I am observing this on KK 4.4.4, if it matters. Any pointers as to why this might be happening?

in your manifest.xml, add android:windowSoftInputMode="adjustPan|adjustResize" under your activity tag.
LIKE THIS:
<activity android:name="......"
.....
android:windowSoftInputMode="adjustPan|adjustResize">
......
/>

Related

EditText Multiline - After hide of Keyboard its Singleline

I have a EditText and if I type some text it will expand to the second line if the Text is too long.
So far so good.
But if I hide the keyboard the EditText converts to a SingeLine and without scrolling behaviour.
What's going on here?
<EditText
android:id="#+id/etNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:fontFamily="sans-serif-light"
android:inputType="textCapSentences|textMultiLine"
android:lines="2"
android:scrollbars="vertical"
android:maxLines="3"
android:textColor="#color/white"
android:textColorHint="#color/background"
android:textSize="25sp"
/>
On typing with keyboard open:
After keyboard hide:
Full XML:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:background="#color/app_color">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:minHeight="#dimen/list_item_height">
<ImageView
android:layout_height="wrap_content"
android:layout_width="72dp"
android:src="#drawable/ic_action_misc_light_24dp"
android:visibility="invisible"
/>
<EditText
android:id="#+id/etNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:inputType="textMultiLine"
android:lines="2"
android:maxLines="3"
android:textColor="#color/white"
android:textColorHint="#color/background"
/>
</TableRow>
</TableLayout>
</merge>
I think I found the problem.
In the main XML where the merge happens I have added by mistake an +id who was already there in another include layout with merge.
I removed that and now it works as it should.
Really strange that I get no error about the doubled +id's!
Old code:
<!-- Note -->
<include layout="#layout/inc_reminder_note" android:id="+id/areaDate"/>
<!-- Date and Time -->
<include layout="#layout/inc_reminder_date_time"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginRight="16dp"/>
New code:
<!-- Note -->
<include layout="#layout/inc_reminder_note" />
<!-- Date and Time -->
<include layout="#layout/inc_reminder_date_time"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginRight="16dp"/>
The layout "inc_reminder_date_time" had also as id "areaDate".

SoftKeyboard hides edittext

I have an EdiText at the bottom of my layout.The issue I was having is that when it gets focus the screen shifts upwards to give space to soft keyboard.To resolve it I added
android:windowSoftInputMode="adjustResize"
inside my Activity declaration in manifest.Now the problem is that the edittext hides behind the softkeyboard although screen doesn't shifts.
If instead I put
android:windowSoftInputMode="adjustPan"
then the activity's main window shifts upward which i don't want.
How can i resolve this in such way that when EdiText gets focus activity's main window does NOT shift upwards to make room for the soft keyboard but the main window is resized including the EdiText so that keyboard comes below EdiText as seen in many apps.
Layout
<?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"
android:background="#color/background_feed">
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical" />
<ListView
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F7F7"
android:paddingTop="10dp"
android:layout_above="#+id/border_view_comment"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"
android:paddingBottom="10dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
<TextView
android:id="#+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/no_comment_msg"
android:visibility="gone"/>
<View
android:id="#+id/border_view_comment"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/commentlayout"
android:background="#C7C7C7"
android:visibility="gone"/>
<RelativeLayout
android:id="#+id/commentlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/comment_box_shadow"
android:padding="10dp">
<ImageView
android:id="#+id/commentor_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="15dp"
/>
<ImageView
android:id="#+id/clickPostComment"
android:layout_width="30dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:src="#drawable/post"
android:textColor="#color/white" />
<EditText
android:id="#+id/commentsPost"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignTop="#id/commentor_image"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/clickPostComment"
android:layout_toRightOf="#id/commentor_image"
android:background="#drawable/comment_edittext_bg"
android:hint="Comments"
android:singleLine="true"
android:maxLength="140"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/title_gray"
android:textColorHint="#d5d5d5"
android:textSize="15sp" />
<ImageView
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_alignTop="#id/commentsPost"
android:layout_marginLeft="10dp"
android:layout_marginRight="-2dp"
android:layout_toLeftOf="#id/commentsPost"
android:scaleType="fitStart"
android:src="#drawable/comment_shape" />
</RelativeLayout>
</RelativeLayout>
make your view scrollable by embed your view inside Scrollview
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
.....
add your layout
......
</ScrollView>
If that doesn't help make you root layout as RelativeLayout and design your layout with RelativeLayout

How to move up my controls when they would be hidden by the soft keyboard?

OK, so I have this very basic layout:
As you can see, the edit texts and the login button are centered in the area below the icon. They are not aligned with the bottom. And I want to keep it this way.
Now, when the soft keyboard is shown, all I want is that the whole view is pushed upwards, so that the login button is above the soft keyboard but takes into account its lower margin.
My activity has windowSoftInputMode set to adjustPan, but it just assures that the currently focused control is visible, not all three of them:
Question: What do I need to change so that all three controls are visible as soon as the keyboard is visible?
This is my view:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Recson.Apps.Android"
style="#style/Theme.Recson.NoActionBar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/LoginViewRoot">
<ImageView
android:src="#drawable/Logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Icon"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp"
android:layout_gravity="top" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/Credentials"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_below="#id/Icon">
<EditText
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Username"
android:hint="#string/Username"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textColorHint="#color/text_hint" />
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Password"
android:hint="#string/Password"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textColorHint="#color/text_hint" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/Login"
local:MvxBind="Click Login;Enabled CanLogin"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="30dp" />
</LinearLayout>
</RelativeLayout>
Try to use ScrollView and put your main layout inside it. I think it will do the job.
Try this in Manifest file.
<activity name="ActivityName"
android:windowSoftInputMode="stateVisible|adjustResize">
...
</activity>
As you're experiencing, adjustPan, adjustResize etc will only try to ensure the currently focused input field is visible.
What you could try to do is remove the LinearLayout then position your username password and login views in such a way that the system thinks they occupy the same space by using layout_marginTop and layout_marginBottom.
Just put this in your activity tag of your menifest file:
android:configChanges="screenSize"
And Use ScrollView in your Xml file something like below:
(I have changed your layout a bit):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LoginViewRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/Icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp"
android:src="#drawable/ic_launcher" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnLogin"
android:layout_below="#id/Icon" >
<LinearLayout
android:id="#+id/Credentials"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/Credentials1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:inputType="textEmailAddress" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:inputType="textPassword" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:text="Login" />
</RelativeLayout>
At least, the answers here show that I wasn't missing anything obvious.
I now solved it like that:
windowSoftInputMode set to adjustResize
Complete layout inside a ScrollView
On layout change, I simply scroll down the ScrollView to the bottom:
public class LoginView : MvxActivity, ViewTreeObserver.IOnGlobalLayoutListener
{
private ScrollView _activityRootView;
public void OnGlobalLayout()
{
var focusedControl = Window.CurrentFocus;
_activityRootView.FullScroll(FocusSearchDirection.Down);
if (focusedControl != null)
focusedControl.RequestFocus();
else if (Window.CurrentFocus != null)
Window.CurrentFocus.ClearFocus();
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.LoginView);
_activityRootView = FindViewById<ScrollView>(Resource.Id.LoginViewRoot);
_activityRootView.ViewTreeObserver.AddOnGlobalLayoutListener(this);
}
}
(this is C# code using Xamarin.Android and MvvmCross. It is based on this answer)
This solution has one drawback: The controls are no longer centered in the area below the icon, but right now, I am OK with that:
See it in action
Used This Code :
public MainPage()
{
InitializeComponent();
App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}

Still my layout not shifting up side.

I am trying to shift my layout up when soft keyboard will open.
I have edittext and button. I can see edittext clearly whether keyboard is open or not but problem is that i am showing drop down for edittext. When drop down open it open on top of edittext because there is no sufficient space between keyboard and dropdown.
So i am trying to shift my entire screen up (only edittext will show). So can show dropdown below of Edittext.
I try following things...
I add following attribute in my activity in AndroidManifest.xml
android:windowSoftInputMode="adjustPan"
I add following code in my .java file
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
I read somewhere i need to use relative layout. I also try this but none of them helpful.
Here is my xml code for your reference.
<?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="fill_parent"
android:background="#EFEFEF"
>
<ViewStub
android:id="#+id/vsHeader2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inflatedId="#+id/header"
android:layout="#layout/copyofheader" />
<TextView
android:id="#+id/firstPara"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dip"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text=""
android:textSize="16sp" />
<TextView
android:id="#+id/secondPara"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstPara"
android:layout_marginTop="24dip"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text=""
android:textColor="#666666"
android:textSize="16sp" />
<AutoCompleteTextView
android:id="#+id/mysecondautocomplete"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_below="#id/secondPara"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:layout_marginTop="12dip"
android:ems="10"
android:dropDownVerticalOffset="44dip"
android:windowSoftInputMode="stateHidden"
android:dropDownHeight="290dip"
android:imeOptions="actionSearch"
android:drawableLeft="#drawable/search_grey"
android:background="#drawable/borderforloginedittext"
android:drawablePadding="6dip"
android:hint="Enter Restaurant Name"
android:inputType="textPersonName"
android:dropDownWidth="match_parent"
android:textColor="#cc3333"
android:textColorHint="#999999"
android:textSize="16sp" />
I don't understand why my layout not shifting up. Please give me any hint or reference.
UPDATE:
I just re-read your question and found the mistake you are making. You are adding android:windowSoftInputMode="adjustPan" in AndroidManifestfor resizing or scaling the window for the keyboard.
You should use android:windowSoftInputMode="adjustResize" which will resize the window or adjust the window accordingly.
Try this:
<?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="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF"
>
<ViewStub
android:id="#+id/vsHeader2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inflatedId="#+id/header"
android:layout="#layout/copyofheader" />
<TextView
android:id="#+id/firstPara"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dip"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text=""
android:textSize="16sp" />
<TextView
android:id="#+id/secondPara"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstPara"
android:layout_marginTop="24dip"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text=""
android:textColor="#666666"
android:textSize="16sp" />
<AutoCompleteTextView
android:id="#+id/mysecondautocomplete"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_below="#id/secondPara"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:layout_marginTop="12dip"
android:ems="10"
android:dropDownVerticalOffset="44dip"
android:windowSoftInputMode="stateHidden"
android:dropDownHeight="290dip"
android:imeOptions="actionSearch"
android:drawableLeft="#drawable/search_grey"
android:background="#drawable/borderforloginedittext"
android:drawablePadding="6dip"
android:hint="Enter Restaurant Name"
android:inputType="textPersonName"
android:dropDownWidth="match_parent"
android:textColor="#cc3333"
android:textColorHint="#999999"
android:textSize="16sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Put your entire layout inside a Scrollview. So when the soft keyboard gets open, your view will get adjusted accordingly.

Edittext loses style when align_baseline used

I have a layout where I have RelativeLayout with some Edittext which use the default style and are baseline aligned with some Textfield. The issue is the Edittext are losing the default Holo Light style line (the line under the text). If I take out the baseline then the line is shown though, of course, the Edittext loses the alignment.
I suspect this is bug or at least a very strange behavior, but I will give it a try by asking here in SO :-)
This is how it looks (Edittexts are the blank spaces to the right of Opens and Closes TextViews):
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dip"
android:layout_weight="50"
android:orientation="vertical" >
<EditText
android:id="#+id/store_name_edit"
android:hint="#string/store_name"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_code_edit"
android:hint="#string/store_code"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_group_edit"
android:hint="#string/store_group"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_type_edit"
android:hint="#string/store_type"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_address_edit"
android:hint="#string/store_street"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="20dip"
android:textSize="20sp"
android:text="#string/store_description" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/opening"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_opening_hours" />
<TextView
android:id="#+id/opens"
android:layout_below="#id/opening"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_open" />
<EditText
android:id="#+id/opens_edit"
android:layout_toRightOf="#id/opens"
android:layout_alignBaseline="#id/opens"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:textSize="18sp" />
<TextView
android:id="#+id/closes"
android:layout_alignBaseline="#id/opens"
android:layout_toRightOf="#id/opens_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_close" />
<EditText
android:id="#+id/closes_edit"
android:layout_alignBaseline="#id/opens"
android:layout_toRightOf="#id/closes"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
My guess is the containing RelativeLayout somehow isn't expanding to allow for the lines on the EditTexts to show.
Change the containing RelativeLayout to:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp">
I realise this may not be the best solution but it's a start. Another option might be to try using alignParentBottom instead of baseline on all the "bottom" row elements.

Categories

Resources