I have a somewhat complicated layout, but at the very bottom is a huge EditText. When I click on it to get the keyboard to open, everything slides up just enough to show exactly where the user is typing (as the user begins typing only 1 line is visible, if the user goes to multiple lines then it pans a little more to show 2 lines, etc). I would like everything to pan so that the whole EditText (all the blank space) is visible.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical">
<EditText
android:id="#+id/CommentBox"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:textSize="16sp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:background="#color/transparent"
android:textColor="#color/gray"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
</EditText>
</LinearLayout>
Been struggling with this for a couple days now, would appreciate any suggestions.
Best way to illustrate is with 3 images
This is what the entire screen looks like
This is what the behavior is right now
This is the desired behavior
Hopefully the images illustrate my question. I need to figure out how to make this happen. The only way I have been able to force view to pan to the right place is by setting, android:gravity to bottom , in which case text is written at the bottom. This however, is clearly a very weird user experience. I need text to be like in a normal text box.
Was able to hack together a solution that mimics what I was looking for.
Put the layout inside a scrollView, set the parameter to adjustResize instead of adjustPan. And on click in the editText did
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
} , 250);
Would love to find a non-hacky way to do this, but this is all I've got.
Related
Try stacking two fragments with editTexts on top of each other using an Add Transaction. after that when you press the keyboard imeOption key next button the bottom fragment's edit text can gain focus. this is a security concern. user can type things into the bottom fragments edit text (blindly). I tried the following code:
android:filterTouchesWhenObscured="true"
but it has not helped at least on api 27.
my edit text itself looks like this, nothing special:
<EditText
android:id="#+id/et"
android:layout_width="195dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:imeOptions="actionNone"
android:layout_marginBottom="10dp"
android:hint="#string/enter_name"
android:filterTouchesWhenObscured="true"
android:inputType="textNoSuggestions"
android:textColorHint="#959595"
android:textSize="11sp" />
the issue is very similar to android tap jacking
i tried even doing this:
android:nextFocusDown="#+id/et_two" thinking it would bypass and go directly to the edittext i want. but instead the bottom edit text still gains focus.
the issue solution was surprising. recyclerview was stealing focus. see this SO incident:
adding android:descendantFocusability="blocksDescendants" to the recyclerview stopped the issue.
How does twitter app handle the onclick action on EditText whenever we want to write a tweet? I want to know this because it lets us make a neat user interface and we can manage layout space in a better way.
So my question is that when we click on the EditText, do they launch a new activity?
What I was able to do was that in my layout XML file, I wrote this EditText which moves above the keyboard because of android:layout_alignParentBottom="true"
Like
<EditText
android:id="#+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:lines="5"
android:singleLine="false"
android:hint="Comment"
android:layout_below="#+id/rlrate"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
It looks alright but it still takes up space because it is multiline so I still want to know that whether they are starting a new activity with that layout to post a tweet or is it a fragment? If anyone can explain the functionality then it would be great.
I don't think its the same activity.
I'd do it as follows:
Create EditText - aligned bottom, with an onClickListener. When someone clicks on it start a new Activity with animation - which would have a full screen EditText.
Edit
For animating an Activity - i.e. it slides up when it starts like the Twitter app - then take a look at the answer by Mark Allison
<EditText
android:id="#+id/textbox"
android:singleLine="true"
android:scrollbars="horizontal"
android:scrollHorizontally="true" />
((EditText)findViewById(R.id.display)).setKeyListener(null);
the EditText serves as some kind of log box, text is appended to it at some events.
I need the EditText to be scrolled to the right at all times, I mean the scrollbar should be positioned to the maximum right and so the most recent text is visible.
I cant seem to get it done, not sure how to read the current position of the scrollbar and adjust it accordingly.
I've tried playing with EditText.setScrollX() though even setScrollX(10000) didnt have any effect.
try with
editText.setSelection(editText.getText().length()-1);
I have a layout with a graphic at the top, an EditText in the middle and a button some distance below it, like so:
When the user is typing in the EditText, I want to pan the layout so that the "Go" button is still visible, even if that means clipping the image off the top, like so:
I know about windowSoftInputMode="adjustPan" in the manifest, but that doesn't work because it only pans far enough for the EditText to be visible. Is there a way to make sure it pans until the button is visible too?
For comments with K_Anas, this is my layout. It has all the extra margins and spacing removed compared to the first screenshot, to remove any other source of problems.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:background="#999"/>
<EditText
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Sample..."/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Go"/>
</RelativeLayout>
Spoke with the Android developers hangout, and it doesn't seem like there's an easy way to solve this problem. The consensus seems to be reworking the layout rather than having an API to fix the issue.
did you tried:
android:windowSoftInputMode="adjustResize"
in your activity Tag in Manifest
see these docs on android developer blog
I tried your layout with: android:windowSoftInputMode="stateVisible|adjustResize"
and give me these results:
I'm sure it isn't the BEST way, but couldn't you just change the layout attributes for your button (add/change a margin) and redraw when the edittext is clicked? Use an onClickListener & maybe invalidate your button.
I'm not looking for code, either I won't post any, just an explanation, because I'm kind of lost.
There is this main issue about the resizing when softkeyboard appear.
In my case
I have a listView feeded with 2 editText and many textView with database content using a custom cursorAdapter.
1) AdjustPan
It's pretty simple. When I use the adjustPan property, everything works quite good, except the fact that when I press an editText in my listView and if the listview is bigger than the screensize, I can't scroll. This is actually the normal behaviour and I can understand it.
2) AdjustResize
Here I can scroll as much as I wish.
This property is the one I want to use. But I'm facing 2 issues :
When I press on one of the two editText, I just can't write in. Impossible, even thought it has the focus. I'm forcing the softkeyboard to appear, I try to type some letters in (remember that this editText is focused) but nothing happens.
Again, when I press one of the two editText, it just reorganize (apparently randomly) listview's items. Even thought it's working perfectly with adjustPan, with adjustResize, it's messing with items of the listView.
Any information about one of the 2 issues would be helpful. You can even ask for code, but one more time, I'm just looking for a general explanation that could help. Thanks.
Here this mention issue is same facing me in my app and here some change in my code is this working fine in my app. please try this...
<activity android:name="com.MainActivity"
android:configChanges="orientation|screenSize"/>
<ListView
android:id="#+id/fields_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
/>
<EditText
android:id="#+id/input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:gravity="top"
android:inputType="none"
android:textColor="#color/black"/>