Hard to explain with words, but you can see what I'm talking about easily in Google Hangouts. When you tap in the EditText at the bottom to enter a comment, you see some buttons between the bottom of the EditText and the soft keyboard.
How do you do that? I made a simple layout that has an EditText and a Button below it, but when the user taps in the EditText, the Button is obscured by the soft keyboard. Here's a cleaned up sample:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/StandardMarginSmall"
android:layout_marginBottom="#dimen/StandardMarginSmall">
<EditText
android:id="#+id/NewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
<Button
android:id="#+id/PostComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Post"
/>
</LinearLayout>
Is there a trick into forcing it to keep those buttons viewable while in edit mode?
If you set android:windowSoftInputMode="adjustResize" on your activity, when the softkeyboard is shown, it will push the content of your activity up (resizing it), instead of overlaying on top of your activity. You'll be able to show the buttons then (they'll just be at the bottom of the layout of your activity).
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.
I've one EditText with multi-lines.
The problem is that, while I am adding more and more lines, just pressing ENTER or typing, the EditText keeps scrolling down which is OK, but after approx. 10 lines whole activity is scrolling.
And when I click again on EditText, the opened keyboard covers whole EditText.
But, when I click only on 3rd line, keyboard isn't covering EditText and View is moved like it should have.
Any advice please?
Okay,Using EditText in ScrollView Like this way
<ScrollView
android:layout_height="100dp"
android:layout_width="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#54D66A"
android:textSize="17sp" />
</ScrollView>
For programmatic approach please check
http://developer.android.com/reference/android/text/method/ScrollingMovementMethod.html
You can give android:maxHeight="60dp" to your EditText to stop scrolling of the whole Activity and it will solve other problem also.
I hope it helps.
I have a table whose tapping on a cell changes its content and displays some edit texts. The first of these edit texts requests the focus, but oddly when I tap on it, the keyboard doesn't show. It is when I tap the others edit texts though. What should I do? Here is how I implemented my first edit text.
<EditText
android:id="#+id/editContent"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="top"
android:inputType="textMultiLine" >
</requestFocus>
</EditText>
When I don't request the focus, there is also a strange behaviour: it opens the keyboard when I tap it but my edit text loses the focus and I've to tap it again to write in it.
I found the problem, it was because of this line in the Activity block of the Manifest :
android:windowSoftInputMode="stateHidden"
I changed it by :
android:windowSoftInputMode="adjustPan"
Works well now.
I use following GUI setup:
ListView activity
CursorAdapter that feeds this list
Layout for activity
Layout for rows in ListView :
<?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:gravity = "right" >
<TextView android:id="#+id/text_9_description_top"
android:layout_width="wrap_content"
android:layout_height="fill_parent" android:gravity="right|center_vertical"
android:layout_alignParentLeft="true">
</TextView>
<CheckBox android:id="#+id/chkApprovedTabChapter9"
android:layout_toRightOf="#+id/text_9_description_top"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:gravity="right" >
</CheckBox>
<Button android:id="#+id/tabchaprter9_row_button_delete"
android:layout_height="wrap_content" android:text="leftBtn"
android:layout_width="wrap_content" android:background="#android:drawable/ic_menu_delete"
android:layout_toRightOf="#+id/chkApprovedTabChapter9" >
</Button>
<Button android:id="#+id/tabchaprter9_row_button_edit"
android:layout_width="wrap_content" android:layout_toRightOf="#+id/tabchaprter9_row_button_delete"
android:text="rightBtn" android:layout_height="match_parent"
android:background="#android:drawable/ic_menu_edit">
</Button>
<EditText android:layout_width="wrap_content"
android:id="#+id/text_9_description_bottom"
android:layout_toRightOf="#+id/tabchaprter9_row_button_edit"
android:layout_height="match_parent" android:gravity="right"
android:layout_alignParentRight ="true"
android:inputType="text"
android:imeOptions="normal">
</EditText>
</RelativeLayout>
Row Layout contains EditText, checkbox and couple of buttons. ListView is filled with setAdapter (). Apparently ListView is created correctly, I see all rows with data.
First problem : I would like to initially show EditText as disabled so user cant edit text immediately. Only after clicking on "edit" button in the row EditText must became available for typing. Setting enable "false" has no effect on EditText (tried bot in code and in XML attribs) EditText is always editable.
Second issue: Typing in EditText using softkeyboard looks fine - I see all changes, however when I close softkeyboard (either pressing Android back button or "hide" button on keyboard) all added text is removed and EditText is reverted to its initial stage.
rather than enabling and disabling it try with focussable= "false" this will have desirable effect.
For first issue: add this attribute in XML file android:visibility="invisible"
And in the edit button onClickListener make the visibility as edit.setVisibility(View.VISIBLE).
make it clear for 2nd issue
first problem : you cannot disable EditText, write code to show TextView and hide EditText for disable EditText mode and vice versa for enable mode.
Second Problem: go to setting -> language and keyboard under text setting disable other languages and keep Android Keyborad on.
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="#+id/name" android:singleLine="true"
android:maxLength="12" android:capitalize="none" android:inputType="text" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/search_button"
android:text="Search" />
I have this at the top of my application. When the application starts, the EditText is orange highlighted and has a cursor in it; when the EditText is tapped, the soft keyboard pops up. The user uses it to type into the EditText.
However, when they click the Button, my onClick method fires and does everything it's supposed to, however the soft keyboard stays on screen and the EditText is still highlighted with its cursor.
I also have, at the top of the Button onclick:
findViewById(R.id.name).clearFocus();
In spite of this, the EditText does not seem to clear its focus. How do I make the button actually act as if it is submitting the form?
Also, I do not transition to a different Activity on the click of the Button. I suppose that is the typical case, and probably the reason why they don't bother hiding the keyboard. However I want to keep the search box and button at the top of the screen, so I just dynamically fill and add views to the screen when the Button is pressed.
How can I achieve my desired behavior?
You can hide the keyboard by calling this.
InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);