I hava a long TextInputEditText in a TextInputLayout in a ScrollView, When I click at the start of the text to set the cursor position on the first line, but suddenly screen scrolls to bottom. see GIF below:
Now if I remove Material box style from TextInputLayout, everything is ok. No sudden scroll on first line click.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilDescription"
<!--style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"-->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:hint="Product Description"
app:counterEnabled="true"
see this GIF, when I remove style attribute:
What's wrong with outlined Box style?
Caution: I don't want to change windowSoftInputMode in AndroidManifest to adjustPan, I should use adjustResize because I have some other stuff which keyboard shouldn't appear on top of them.
For multi-line TextInputEditTexts that might be taller than the screen (especially after the soft keyboard is shown), you need to add the following to your TextInputEditText
app:textInputLayoutFocusedRectEnabled="false"
as described here: Android TextInputLayout writing focus issue when height is bigger than the screen
Related
I have a simple TextInputLayout:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilPwd"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Passcode"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" >
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
Then I have other views below.
The issue is that when I set the error on the TextInputLayout the height increases and pushes all the views below.
I tried a workaround setting a blank helperText, but when in talkback the blank helperText will be read and that's not what I want.
Is there a clean solution other then wrapping the TextInputLayout in some ViewGroup with a set height?
After a day of tries, I actually found the solution:
public void setHelperTextEnabled (boolean enabled)
Whether the helper text functionality is enabled or not in this layout. Enabling this
functionality before setting a helper message via
setHelperText(CharSequence) will mean that this layout will not change
size when a helper message is displayed.
Basically it occupies in advance the space of the helperText (even if it's not set), and that's the same space occupied from the error.
Worth to notice that the equivalent xml attribute "app:helperTextEnabled" does not solve the issue.
Yes, When you enable the error attribute of TextInputLayout, it will always increase the height of the View to show the error(whenever occurred), which will cause other Views/ViewGroups to push further below.
What you can do to get rid of the extra space is set the error programmatically.
For example, whenever an error occurred(or whenever if you want to set the error) you can call
setErrorEnabled(boolean value)
so that it can also show the error and will push other views down (which are below it), and if the error is gone(or you want to hide error), then you can call
setError("")
where you need to pass an empty string and then call the setErrorEnabled(false), so the textInputLayout will come back to its original position.
I had the same problem and solved it by adding this XML attribute.
app:errorEnabled="true"
I have one activity an in this activity i have one BottomSheet.
In the bottomsheet layout there is button below the editext .
when keyboard is opened then in that case button is hiding behind the keyboard . and when i scroll then the button is visible. what i want is that the button should be always above the keyboard
This is the autocomplete suggestion area of your softkeyboard. Use "textNoSuggestions" flag to your inputType property.
<EditText android:id="#+id/inputName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:hint="#string/inputName" />
Note: Here you can combine multiple flags in inputType like this,
android:inputType="textPersonName|textNoSuggestions"
Just add |textNoSuggestions flag to the end of the inputType property.
Add this line in to your Edittext
android:inputType="textNoSuggestions"
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'm using an EditText inside a TextInputLayout, but after upgrading the support library to 23.2.0, I get this warning in the logcat, What's the difference between a regular EditText and a TextInputEditText? I can't seem to find any documentation for it.
I was wondering this too, Daniel Wilson gathered the documentation, but to the untrained eye it doesn't mean much. Here's what it's all about: "extract mode" is referring to the type of view that's shown when the space is too small, for example landscape on a phone. I'm using Galaxy S4 with Google Keyboard as input method editor (IME).
Landscape UI without visible IME
Based on the focus (on Description) you can see TextInputLayout in action pushing the hint outside the editor. Nothing special here, this is what TextInputLayout is supposed to do.
Landscape UI editing empty Name field
Editing the Name you can see that the IME doesn't give you a hint of what you're editing.
Landscape UI editing empty Description field
Editing the Description you can see that the IME gives you a hint of what you're editing.
Layout XMLs
The difference between the two fields is their type EditText VS TextInputEditText. The important thing here is that TextInputLayout has the android:hint and not the wrapped EditText, this is the case when TextInputEditText's few lines of Java code makes a big difference.
Name field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
>
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
Description field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Description"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="4"
android:scrollbars="vertical"
/>
</android.support.design.widget.TextInputLayout>
There is no documentation for it, but the class is a regular EditText with a single extra feature:
Using this class allows us to display a hint in the IME when in 'extract' mode.
Specifically it sets the EditorInfo.hintText. You'll notice in the TextInputLayout class you can specify the hint and it's appearance rather than as part of the child EditText widget.
If you need to do that, you should use a TextInputEditText so it pays attention to the hint info you specified in the TextInputLayout.
They are essentially the same thing, but I think the TextInputEditText has more features and possibly attributes. I changed to the TextInputEditText and everything worked and looked as it did before with the standard EditText.
The only difference is that when your device is in landscape mode, TextInputEditText will show the hint, EditText won't.
I had this problem and just deleted this line in my xml file:
android: fitsSystemWindows = "true"
and the error disappeared.
This is the picture:
When I click on the "Confirm password" EditText, for the first time, it works the way it should - layout pops up so I can enter text in selected EditText, but when I dismiss keyboard(that EditText still focused) and click on that same EditText again, it stays under keyboard.
Main layout is RelativeLayout, input fields are in ScrollView and buttons are in LinearLayout aligned to parent bottom.
In manifest I have android:windowSoftInputMode="adjustPan".
Is this some Android issue or I've been doing something wrong?
It's actually a bug in EditText. try removing gravity of EditText, which could be either center_horizontal or center
Got the answer from another question. check this.
For me removing android:minWidth does the trick
I just came with a workaround for this problem as well, I got my edit text to start the text in the middle of the screen with a not so great solution, but it works for me. The code is this one:
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingStart="130sp"
android:paddingEnd="50sp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:gravity="bottom"/>