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"
/>
Related
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.
I use TextInputLayout (+ search) in my NavigationDrawer. When user toggle this drawer, the cursor focus appears immediately on TextInputLayout field.
Is it possible not to get focus on this field until user will click on it?
Thanks !
in your root view use this attribute:
android:focusableInTouchMode="true"
None of the answers helped in my case. What I did was the following:
editText.post(() -> {
textInputLayout.setHintAnimationEnabled(false);
editText.clearFocus();
textInputLayout.setHintAnimationEnabled(true);
});
This is available starting from design support library v23.
Put this in your onCreate():
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or add this into your manifest in your activities entry:
android:windowSoftInputMode="stateHidden"
I fixed this problem , just add another EditText and hide it
<EditText
android:layout_width="0dp"
android:layout_height="0dp" />
<android.support.design.widget.TextInputLayout
android:id="#+id/NghiPhep_TextInputLayout_GhiChu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextHintLabel"
android:layout_marginTop="5dp"
android:focusableInTouchMode="true"
>
<EditText
android:id="#+id/NghiPhep_txt_GhiChu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorPrimaryDark"
android:hint="Ghi chĂș"
android:fontFamily="#font/arial_rounded"
android:inputType="textMultiLine"
android:singleLine="false"
android:textSize="18sp"/>
</android.support.design.widget.TextInputLayout>
I have an input box - edittext in android, which is not single line. I want that when three lines are complete then the edittext should stop expanding and scrollview should attach to the edittext at that time.
I can add scrollview directly?
try like this way
<EditText
android:id="#+id/users_first_name"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:hint="First"
android:focusable="true"
android:inputType="textPersonName"
android:enabled="true"
android:maxLines="3"
>
</EditText>
use android:maxLines="3" for your EditText tag in xml.
I want to have a Button or a clickable View in my EditText so that I can perform some action on click of it. I was able to put a drawable inside my EditText thanks to Marcosbeirigo for this answer. But, now I want to make it clickable so that I can perform some action on it. I know this is possible as HTC uses buttons inside EditText in their stock sms app as shown in the following image-
In my case, the button will be positioned anywhere, can be in the center also. But the main thing is how can I put a button in EditText?
Use RelativeLayout. The Send and Attach buttons are simple Android Buttons and the 32/160 is a TextView. Put the buttons and the textview on the EditText object, play with the layout arrangments and set some right padding to the EditText object so that the text inside it won't go under the buttons.
You don't need any drawable and listening to the click event of the android buttons is not a question anymore.
Its absolutely correct
Use this , It worked for me -
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/id_search_EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:paddingRight="40dp"
android:hint="Enter your feelings and connect" />
<ImageButton android:id="#+id/id_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/id_search_EditText"
android:layout_alignBottom="#+id/id_search_EditText"
android:layout_alignRight="#+id/id_search_EditText"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
I think you try to search set click event for compound drawable. You can find some solutions here
handling-click-events-on-a-drawable-within-an-edittext
there is no button inside editText It's just an editText with white background so you don't see it's margins and a simple layout arrangement.
The only possible solution is to use a RelativeLayout that allow you to put also Views in overlay to others. Other Layout wont allow you to do such things.
Also I found this tutorial: http://developer.android.com/resources/articles/layout-tricks-merge.html maybe it can helps you :)
Use this this code may work.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/REFReLayTellFriend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editext_rounded"
android:drawableLeft="#android:drawable/ic_menu_search"
android:gravity="start"
android:hint="Search"
android:singleLine="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtSearch"
android:background="#drawable/ic_action_content_filter_list"/>
</RelativeLayout>
</LinearLayout>
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