I have an EditText that is wrapped in a TextInputLayout that is inside a LinearLayout and I want to show a fragment when the LinearLayout is touched. However the EditText is intercepting the touch.
I tried setting focusable="false" and clickable="false" on the EditText and the TextInputLayout but now the touch doesn't do anything except change the hint color slightly for a little bit.
I don't want to set enabled="false" because of the grayed out style color changes.
My xml:
<LinearLayout
android:id="#+id/type_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:id="#+id/type_input_layout"
android:clickable="false"
android:focusable="false">
<EditText
android:id="#+id/type_input"
android:hint="Type"
android:text="Public"
android:clickable="false"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|textMultiLine"
android:background="#color/transparent"
android:gravity="left"
android:textSize="22sp"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
My solution for now: just put a view on top of the edittext
try this ,may be its working
set in your linear layout
android:clickable="true"
set in your editText
android:clickable="false"
android:focusable="false"
remove from TextInputlayout this 2 lines
android:clickable="false"
android:focusable="false"
Try android:enabled="false". I'm not sure but it might work.
Try using android:descendantFocusability="blocksDescendants" on your LinearLayout to make children view not focusable.
You can also try using both focusable properties
android:focusable="false"
android:focusableInTouchMode="false"
EDIT:
Try android:duplicateParentState="true" for every child view of the LinearLayout. You can also look at this question. There is someone mentioning that inputType on EditText can intercept the click.
In xml for EditText you should declare:
android:clickable="false"
android:longClickable="false"
This will make it not able to take over the click.
Related
I have a ListView look like the following, and each entry consists of two normal TextViews and one toggle button.
I want to add a floating hint and a word counter for the TextViews on each entry. So, I changed the TextView to TextInputEditText, and they look like the following:
The problem is after I use TextInputEditText, the onItemClickListener no longer responds to clicks. I tried different settings for android:descendantFocusability="blocksDescendants" on the list entry, and also tried android:focusable="false" and android:focusableInTouchMode="false" on the TextInputEditText.
What settings do I need to make TextInputEditText completely disabled/un-editable like a regular TextView while keeping its nice floating hint and word counter?
Code for normal TextView, which works well with onItemClickListener
<TextView
style="#style/bodyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/thin_boarder"
android:text="TestName 1"/>
code for TextInputEditText which does NOT work with onItemClickListener
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="top|start" />
</com.google.android.material.textfield.TextInputLayout>
This is my current xml layout:
<android.support.design.widget.TextInputLayout
android:id="#+id/emailAddressLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:focusable="true"
android:clickable="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:padding="5dp"
android:focusable="false"
android:clickable="false">
<AutoCompleteTextView
android:id="#+id/emailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:hint="email address"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1" />
<Button
android:id="#+id/emailTextClearButton"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_gravity="end|center_vertical"
android:background="#drawable/ic_clear_black_svg" />
</FrameLayout>
</android.support.design.widget.TextInputLayout>
I need my FrameLayout in order to accomplish a (x) clear button within my AutoCompleteTextView.
The problem is that the FrameLayout is negating the effect of TextInputLayout so the text is not pushed up when user inputs text or clicks on AutoCompleteTextView.
Current result: (Missing Email address header text)
Wanted result: (I added an x clear button to show what's missing when not using FrameLayout)
TextInputLayout has some internal behavior that isn't exactly what you'd expect from a "normal" ViewGroup. Most of it is undocumented, but the Javadoc for the class itself does tell you a little bit:
Note: The actual view hierarchy present under TextInputLayout is NOT guaranteed to match the view hierarchy as written in XML. As a result, calls to getParent() on children of the TextInputLayout -- such as an TextInputEditText -- may not return the TextInputLayout itself, but rather an intermediate View. If you need to access a View directly, set an android:id and use View#findViewById(int).
What you should take away from this is that TextInputLayout will both potentially "re-write" your declared XML layout and also that you should do your best to make sure that your XML layout is set up in the way TextInputLayout "expects".
I believe that your specific problem stems from the fact that your XML layout specifies no EditText that is a direct child of the TextInputLayout. If you look at the source for TextInputLayout#addView(), you'll see this:
#Override
public void addView(View child, int index, final ViewGroup.LayoutParams params) {
if (child instanceof EditText) {
...
setEditText((EditText) child);
} else {
...
}
}
Because you have a FrameLayout wrapping the EditText, that call to setEditText() is never made. Therefore, none of the special functionality of TextInputLayout will work.
How to solve this is a more difficult question. I would start by changing your layout to have this structure instead:
<FrameLayout>
<TextInputLayout>
<EditText/>
</TextInputLayout>
<Button/>
</FrameLayout>
This way you can have a "normal" TextInputLayout hierarchy and a button to clear the text. You'll have to do a little more work to position the button so that everything looks natural, but this should be a workable starting point.
I ended up solving my question using the following in my XML:
<android.support.design.widget.TextInputLayout
android:id="#+id/emailAddressTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<AutoCompleteTextView
android:id="#+id/emailAddress"
style="#style/body_text_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/prompt_email_address"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"/>
<!--work around solution using negative marginTop-->
<Button
android:id="#+id/emailTextClearButton"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end|center_vertical"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
//work around solution
android:layout_marginTop="-32dp"
android:background="#drawable/ic_clear_black_svg"/>
</android.support.design.widget.TextInputLayout>
The WORKAROUND is to set my button underneath my AutoCompleteTextView and use a negative marginTop on the button to be able to set it where it needs to be set.
Result:
Note: I'm using a RelativeLayout as parent of TextInputLayout
I have a TextView that takes in Strings and I want the TextView to scroll to the last text added on the right automatically. The ScrollView works but I have to scroll manually to the last text added when it's out of the TextView's field of view. Please help.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:fillViewport="true"
android:scrollbars="none">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:scrollHorizontally="true"
android:textColor="#android:color/black"
android:textSize="24sp" />
</HorizontalScrollView>
yourScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
I solved this problem through the use EditTextView instead of TextView and disabling focusEnabled by setting keyListener to null in order to achieve the behavior of a normal TextView and also scroll automatically like I wanted.
I know that is possible to disable editing EditText.
Answers is here, and here.
But, when i disable EditText it also disabled vertical scroll in this text.
Is it possible to disable only editing, but allow scrolling?
editText.setFocusableInTouchMode(false);
editText.clearFocus();
Use this porperties in your EdittText:
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
Your EditText will be enable, but not focusable for edit. Then, you will able to scroll (in vertical on this case) and will not able to edit.
I've found that just disabling the key listener, focusable and cursor seems to work:
editText.setKeyListener( null );
editText.setFocusable( false );
editText.setCursorVisible(false);
As long as you keep the edit text enabled you seem to be able to scroll the text still.
If you wrap your EditText in a ScrollView then you should be able to preserve the scroll behavior.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText ... />
</ScrollView>
editText.setKeyListener(null) should help you.
Try to use these two attributes to your editext it will make your editext only scrollable not editable
android:inputType="none"
android:textIsSelectable="true"
Below is the example
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:padding="20dp"
android:layout_margin="10dp"
android:textSize="#dimen/text_size"
android:inputType="none"
android:textIsSelectable="true"
android:textStyle="normal"
android:id="#+id/toeditext"
android:textColor="#android:color/white"
/>
I have a ListView with EditText in each row. So I cannot type anything in any EditText as well as not focus when tap on them.
Xml souce:
<EditText
android:id="#+id/textValue"
android:layout_width="match_parent"
android:layout_height="37dip"
android:editable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="left|center"
android:inputType="text">
</EditText>
Thanks in advance.
If you want to be able to focus on the EditTexts, remove the lines that set it as non-editable:
android:focusable="false"
android:focusableInTouchMode="false"
Use TableLayout instead of ListView because EditText has focusable problems in ListView.
you made the EditText unfocusable with those two lines:
android:focusable="false"
android:focusableInTouchMode="false"
just remove or set the value to "true" in order to use them