selection markers on textview in android - android

I have used textView.setTextIsSelectable(true) or android:textIsSelectable="true" on textview. It is working somewhere but on some textviews it is showing the below error.
W/TextView: TextView does not support text selection. Action mode cancelled.
I have tried
android:focusable="true"
android:focusableInTouchMode="true"
Also on textviews but it is also not working, can you please help me to figure out why it is working on some textviews and not working on others.
Thanks a lot in advanced.

As answered by Yojimbo here:
If TextView, have you tried textView.setTextIsSelectable(true);
Or if EditText, editText.setSelectAllOnFocus(true);
Hope this is Help you.

Related

ellipsize enabled line text is cutting from left side

I am writing text description in two lines using TextView. I am using android:gravity="center" to centrally aligned two lines & also used android:maxLines="2" & android:ellipsize="end" attributes in xml file. First line is coming properly but at left side of second line text is getting clipped. If I remove android:ellipsize="end" attribute then there is no any text cut. So i am thinking that my problem is because of ellipsize attribute. I tried a lot of experiments to solve this issue, but not succeeded. Can anybody help me to solve my issue.
Apparently, there is an incompatibility between the attributes ellipsize, maxLines and letterSpacing.
I had exactly the same issue, and setting the next line solved the issue.
android:letterSpacing="0"
Hope this helps :)

Not able to enter values in EditText

I'm a newbie in Android development. Recently I have been facing a problem in the EditTexts(eventhough I havent changed any attributes of EditText) used in my app which I'm currently running in Emulator.
On clicking the EditText it receives focus, but on typing something the focus changes to some other view. But I'm able to enter values if I navigate to EditText using Tab button of the keyboard. This happens to all EditTexts in my application.
Surfed net for getting a solution, but did not find one.Help...
Implementation of one of my EditText:
<EditText
android:id="#+id/edittext_testname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hintEditText1"/>
Thanks in advance.
Ever tried your app on a physical device?
However, I cannot see anything wrong with your EditText xml. Perhaps there is some java code in your activity catching any events related to that EditText? Or maybe to the other view element you mentioned getting the focus?
I had a similar issue but with a custom style I had defined for my EditText. How I fixed it?
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
So try applying the "android:focusable" and "android:focusableInTouchMode" properties and see if it makes any difference. They should be applied to the EditText by default but give it a go.
(I would have posted this as a comment but I need more rep)

How to set multiline,firstletter caps and disable suggestions on edittext

I have an edittext for reply to email. i want to give three properties for edittext like Multiline, First character caps and disable word suggestions.
I gave like this in xml...
android:inputType="textCapSentences|textVisiblePassword"
I tried in code also... etMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
I am not able to give multiline....how can i achieve this
thanks
I found solution for this problem
Just set the following parameters in xml file..
android:inputType="textCapSentences|textVisiblePassword"
These are for setting first letter of sentence to caps and disable suggestions
and write following code in ur Activity
edittext.setSingleLine(false);
Try setting android:inputType="textMultiLine|textCapSentences|textVisiblePassword". What might be happening is that it is multiline but only one line is currently shown, in which you could say android:minLines="5" or so.

Hyperlink for textview in android

I want to create a hyperlink to textview in android. So in my layout I have given android:clickable="true" to the textview. Previously it worked for my other layouts. But now it is not working. When I am clicking on the textview it remained as it is.What may be the problem?
Please help me.
Have you tried Linkify class? Here is explanation from android developers. Also android:autoLink property of TextView might be helpful/
You can use textview.setOnClickListener. This is useful for you may be.

Custom Position of Hint in Edit Text box.

I was wondering if there was any way that I could get a hint at the bottom of an Edit Text view -- and then the user to start entering text at the top of the box.
As a bonus question, is there any way I can make the hint NOT disappear once the user starts entering text.
You can set the position of the text using the "gravity" attribute (as noted at http://developer.android.com/reference/android/widget/TextView.html#setGravity(int)). So to put the text at the bottom you would have;
android:gravity="bottom"
And to answer your bonus question; No, you can't display the hint when text is entered into the edit text view. Displaying the hint only when the box is empty is the defined behaviour as noted at http://developer.android.com/reference/android/widget/TextView.html#setHint(int)
(and yes, I know the links are for TextView, but EditText derives all of its' text positioning and hint handling functionality from TextView).
Actually THERE IS a way to prevent hint from hiding, and it's a cool one :-)
It gives you the Floating Label look with smooth animation very easily and it's from android itself. No extra libraries and stuff.
Try this:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Touch me and I'll fly!"/>
</android.support.design.widget.TextInputLayout>
You can change the behaviour using other xml tags like android:gravity="start|center|end" and others.
As a BONUS, you can use error messages with it :-) Here's the link to that question: https://stackoverflow.com/a/30953551/6474744
And sorry I do not have enough reputatuion to post images, so help yourself:
http://i0.wp.com/androidlift.info/wp-content/uploads/2015/09/Screenshot_2015-09-28-17-03-561.png
Enjoy :-)
The problem with using both android:gravity and android:hint is that they are inter-linked with regard to cursor position.When you position the hint using gravity and you start entering text, it is entered in the same position as the your hint which is a problem if you want it to start traditionally on the top-left corner.

Categories

Resources