I want to make EditText or Textview selectable in my android project .
project is for android 4.0+ . I add this : txtView.setTextIsSelectable(true) and also : txtView.setCustomSelectionActionModeCallback(new myCallback());
to make my custom selection menu .
but this error happend when i want to select the text .
W/TextView﹕ TextView does not support text selection. Action mode cancelled.
i searched about the error but didn't find the solution .what should i do ?
<TextView
android:id="#+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="" />
*API Level 11 and up only
setTextIsSelectable does fix the problem on Android 7.1.1 for sure. The setEnabled(false) and then true didn't work.
editText.setTextIsSelectable(true);
My exact situation was having setFocusable(false) and adding an onClickListener, then setting setFocusable(true) and onClickListener(null) gave me the error in the OP.
(not correct syntax but you get the idea)
Related
I have noticed that since a few days, all my TextInputLayouts have the "error exclamation point" always enabled. I haven't changed anything about those TextInputLayouts for a long time, so I really don't understand what is happening.
Here is a screenshot of how it looks:
Do you have have any idea what could be the source of this issue? Did something recently changed with the TextInputLayouts?
Thank you very much in advance
EDIT
Here is the related code:
The .xml file is really simple. It's a list of TextInputLayouts and EditTexts like this:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/default_margin"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginRight="#dimen/default_margin">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/txtAddressTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/PROFILE_SCREEN_ADDRESS_INPUT_TITLE"
android:inputType="textPersonName|textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
Also, there absolutely no mention of setError() in my Kotlin code.
You can try this. But It will permanently remove the error Icon. If you want to show it again you have do it programmatically.
app:errorIconDrawable="#null"
Edit:
It looks like it's fixed with com.google.android.material:material:1.2.0-alpha04.
Ho, I found the issue. I actually updated the version of the Material library from version com.google.android.material:material:1.1.0-alpha08 to com.google.android.material:material:1.1.0-alpha09.
Google changed the behaviour of Text Field (see here: https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha09):
Text Field:
Adding option to set TextInputLayout icons to be not checkable (6a88f2b)
Implementing error icon for text fields (3f73804)
I want my ToggleButton to like like this .
But with this code , it always shows me the older toggle button.
Am running the code in Emulator with API 21 only, Am I missing something here. My code snippet is
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Found a solution.
Using Android support library. Code snippet is..
<android.support.v7.widget.SwitchCompat
android:id="#+id/id_useridview_switch"
android:layout_marginTop="24dp"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:theme="#style/colortoggle"
/>
Thanks Selvin, got a clue from ur and on what to search
In this code you just set the width and height of your toggle button!
for Android L toggle button you should use support libraries to achieve that!
google something like these:
android L Toggle button support libraries
Also search in Github.com
Use Switch instead of toggle button you will get what u need. No need for external libraries
I need edittext with auto suggestion turned on.
For this I am using following in xml :
<EditText
android:id="#+id/edt_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="#string/description_album_hint"
android:imeOptions="actionNext"
android:inputType="textCapSentences|textAutoCorrect|textAutoComplete"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:textColor="#color/black"
android:textColorHint="#color/hint_color_light_gray" />
Even if I add "textCapSentences|textAutoCorrect|textAutoComplete" as inputType still there are no suggestions.
Adding Screenshot (this is what I need to implement):
Please help me.
Thanks in advance.
For this purpose you need a subclass of EditText called AutoCompleteTextView. You can find an example here http://developer.android.com/guide/topics/ui/controls/text.html#AutoComplete
If you want to get auto suggestions in top of your keypad, what ever you are following is correct. Additionally you can add android:autoText="true". The suggestion will show you all your previously entered words.
Else if you want to get suggestion for every letter you type, then you can use AutoCompleteTextView.
Here is the code, how you can use this.Ex - AutoCompleteTextView
Got it .....
just removing "textAutoComplete" from "textCapSentences|textAutoCorrect|textAutoComplete" worked for me.
I have a ListView in Activity, and in each item , I insert an EditText for show my text.
I need drag the handle to select text & copy the text, but can not edit text.
On Android ICS, How can I do this?
text.setTextIsSelectable(true) requires API 11. For those using lower API's:
In xml use:
android:inputType="none"
android:textIsSelectable="true"
This will make your EditText uneditable but selectable.
I think you could override the onKeyDown() method, make it do nothing but return true. It should catch the keypresses from the keyboard and negate them before they can go into the text in the EditText.
You might also try setting editable to false like this
android:editable="false"
on the EditText in your xml layout. However I am not certain if this will let you still highlight and copy, but it is worth a shot.
I resolved this problem.
Just set TextView like this:
text.setTextIsSelectable(true);
Althouth android:editable is deprecated and Lint suggests to use inputType, It doesn't seem to work. So android:editable="false"is apparently the best possible solution for all android versions.
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:editable="false"
android:textIsSelectable="true"
tools:ignore="Deprecated" />
I'd like to add a Button like this one below into my ListView when the list is empty using the setEmptyView() method.
Is there a built-in style in Android for this? Because I noticed that a few apps are using exactly the same Button style.
Look at this link: Add Items to ListView - Android
It shows the correct Android resource to use, which shows a green "+" symbol on the ImageButton.
To be precise:
<ImageButton
android:id="#+id/moreImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:contentDescription="#string/image_button_delete"
android:src="#android:drawable/ic_input_add" />
Short answer: No, this is not a standard Button.
However, you can add a similar Button by using an ImageView. You just have to design/download something you like.