I have an EditText which I want to be editable and selectable, just like any other EditText. My theme is
...Light.NoActionBar
so I need an extra ActionBar for the Copy/Paste etc. when the text is selected.
So I use
editText.setTextIsSelectable()
and it works, but when I enable it, the textView becomes ineditable!
To make it editable again, I use the following
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);
editText.setClickable(true);
editText.setLongClickable(true);
but it doesn't help! Also, it doesn't make a difference whether I assign these tags in the .xml or in the code, I tried that...
I guess the solution is pretty simple, but the API docs and google didn't tell me how to make it editable again... It seems like noone ever had that problem before
EDIT:
xml:
<EditText
android:id="#+id/etMitspieler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Players"
android:inputType="textPersonName"
android:text="test"
android:textColor="#android:color/background_light"
some constraint stuff... />
Related
I have a layout where I want to show a bunvh of edit texts and a date picker. Since I want to have the same design for all fields, I figured out that I need to user an edit text for date picker too but make it non editable but clickable. Below is the xml code of my edit text that will be used to show the date picker :
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/notification_layout"
style="#style/Theme.Connect.InputFieldLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startIconDrawable="#drawable/ic_stk_notification_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/notification_edit_text"
style="#style/Theme.Connect.InputField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notification"
android:maxLines="1"
android:lines="1"
android:cursorVisible="false"/>
</com.google.android.material.textfield.TextInputLayout>
I tried many solutions I found on the internet, I did managed to make edit text non editable but without the ripple click effect. Is there a way to make the edit text non edditable but still keep the ripple click effect? Is this the best practice to show a date picker consisting the design of the form layout?
Try this and change the `android:focusable` attribute to `false`
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/notification_layout"
style="#style/Theme.Connect.InputFieldLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startIconDrawable="#drawable/ic_stk_notification_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/notification_edit_text"
style="#style/Theme.Connect.InputField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notification"
android:maxLines="1"
android:focusable="false"
android:lines="1"
android:cursorVisible="false"/>
</com.google.android.material.textfield.TextInputLayout>
You can simply use a TextView instead of an EditText and you can set an onClickListener() to it. You can also style it the way you want.
notification_textview.setOnClickListener {
// Whatever you want to do after a click
}
You can get a ripple effect on touch by adding these 2 attributes to your textview
<......Textview
android:background=?android:attr/selectableItemBackground
android:clickable="true" />
You can also add styles to a textview that you wanted to use for the editText.
EditText is disabled, but still it is underlined. Why, how can I remove underline? What exactly underline means? In iOS same component is UITextView but it never underline so the control.
<EditText
android:layout_width="305dp"
android:layout_height="79dp"
android:inputType="textMultiLine"
android:ems="10"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:id="#+id/editText5"
android:text="Do you know y.."
android:enabled="false" />
EditText is disabled
Use a TextView instead.
how can I remove underline?
Use a TextView instead.
Or, use a different background for the EditText, probably. I assume that the Theme.Material/Theme.AppCompat way of supplying that bracket is via the background, as it was with Theme and Theme.Holo. I have not changed the background of an EditText in years, as usually it is not needed.
What exactly underline means?
It tells humans that this represents text that they can edit, as opposed to text that they cannot edit.
I'm using PopupWindow to get some data from users. Surprisingly, I'm unable to select text inside the EditText layout which is the requirement, as I want user to be able to copy(from anywhere) and paste here. I've explicitly used android:textIsSelectable="true" for my EditText. Here are the attributes I'm using for EditText.
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="#+id/emailEdit"
android:inputType="textEmailAddress"
android:textIsSelectable="true"
android:drawableLeft="#drawable/email"
android:drawablePadding="16dp"
android:layout_margin="#dimen/actionable_horizontal_margin"
android:singleLine="true"
android:hint="Email"
/>
I'm also setting popup.setFocusable(true). Is there something else that needs to be done?
My copy paste is working fine for other EditTexts in activities and fragments.
P.S. I don't want to use custom Clipboard actions.
I have this stupid and seemingly trivial problem with the properties of an EditText.
The properties I am trying to achieve for the EditText, are the following:
The contents of the view should NOT contain newlines. It can be text, numbers, symbols, but no newlines.
The soft keyboard should NOT display the enter button because of the above. It should instead display something like "Send" or "Done".
The contents of the view should NOT continue horizontally when reaching the edge of the screen. Instead I want to wrap the text, displaying it on multiple lines.
I have tried many different combinations, but I can not achieve this combination.
What I currently have is this, which is inside a RelativeLayout:
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#id/preparation_text"
android:hint="#string/comment_hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"/>
It achieves 2 of 3. No newlines possible, keyboard displays "Send" rather than the enter-key for me, but the text continues on one line.
Changing inputType="text" to "textMultiLine" wraps text correctly on multiple lines, but also overrides the keyboard to always display the enter button.
I have tried different solutions around the Internet, including setting the properties maxLines="4", singleLine="true" and possible others that I have forgotten again.
I can not find a combination that works.
Output:
Exp:
The op is on right track. I did some research found that some options gets ignored which are specified in XML. but if the same options are set in code then it should do the trick. I used the same XML fragment specified in the question.
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="80dp"
android:hint="hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"
/>
And by adding the following lines in the code, it helped in achieving what you want.
edit_text.setMaxLines(Integer.MAX_VALUE);
edit_text.setHorizontallyScrolling(false);
textShortMessage is the inputType that you are looking for:
<EditText
android:id="#+id/commentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:gravity="left"
android:text=""
android:hint="hint"
android:textSize="16dp"
android:textColor="#android:color/black"
android:lineSpacingExtra="0dp"
android:lineSpacingMultiplier="1"
android:background="#android:color/white"
android:selectAllOnFocus="true"
android:inputType="textShortMessage|textMultiLine|textCapSentences"
android:singleLine="false" />
Refere to this to prevent paste function. To prevent pasting a new line.
Please use android:imeOptions="actionSend"
to solve your problem.
I have the same issue a long time ago, you have to programmatically change Edittext property on OnCreate().
So in XML, create your Edittext like this
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:hint="Comment here"
android:maxLength="400"
android:inputType="textMultiLine" />
And on onCreate() (I wrote in kotlin not Java)
comment_box.imeOptions = EditorInfo.IME_ACTION_SEND
comment_box.setRawInputType(InputType.TYPE_CLASS_TEXT)
Whenever a word is typed in the EditText box, I always see an underline under the word being typed. But when I press a space after that word I no longer see the underline.
My reqirement is to remove that underline when the user is typing the message.
Added is the screenshot and we see that Smith is underlined. But I don't want this to happen.
Below is the xml that I use for the AlertDialog box.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/name_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="#string/alert_dialog_name"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/username_edit"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:inputType="textPersonName"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
android:inputType="textNoSuggestions"
There is a function that removes any composing state. I think if you call it after every time a user types, you will not see the underline. I use it after the user finishes typing, to get the drawing cache of the entire textView (which I need without underline). It's
someTextView.clearComposingText();
You don't have to use any logic to remove the underlines -- just call getText().toString() when you want to use the value. It won't include special formatting or anything.
accepted answer is not given solution, and some other user given answer but no one given full anser, so that's why i write here working solution.
If you want to remove underline then just add below code.
XML
android:inputType="textNoSuggestions"
Java
EditText ed;
ed = findViewById(yourId);
ed.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
If you want to set more than one input type then,
ed.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
May be above information is helpful to others.
The best solution for this is to add on your EditText:
android:inputType="textMultiLine|textVisiblePassword"
Use this from your class, if EditText view is dynamic (created from class file):
EditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
OR include android:inputType="textNoSuggestions" with your EditText in XML.
Read this if you want to keep emojis and textNoSuggestions doesn't work for you.
textNoSuggestions does not work in every keyboard.
inputType="textVisiblePassword" works but it removes emoji's from most keyboards.
I found that setting inputType="textUri" works and keeps the ability to add emojis.
try:
android:inputType= InputTypes.TextVariationVisiblePassword;
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
android:maxLines="1"
/>