How do I put text into empty TextView so it goes away when user starts typing? Just like here in StackOverflow under "Tags" field.
Same approach used in GMail client. That will save me some space - no need to create labels..
Throw an android:hint="hint text" into your EditText xml tag.
As haphazard said or programatically you can use...
setHint(CharSequence hint) or setHint(int resId).
The equivalent to the resource id in xml would be android:hint="#string/hint_text" (for example).
Related
I have two edittext input box. First one is for username and the second one is for password. I want put hint on the inputbox. I have wrote hint with settex() method. In addition, I have wrote
in onclick(view v)
caseR.id.editText_1:
text1.setText("");
break;
in oncreate
text1 = findViewById(R.id.editText_1);
text1.setText("username");
whenever I have click on the input box, hint should dissappear. But, hint is not dissappeared. Now, is the way I am doing wrong? Or I have missed something?
Use
text1.setHint("MyHintString");
instead. setHint() provides the hint that disappears when the user types something. You can also use a String resource ID or an xml based approach, but in your case, using the String method will suffice.
Only use setText() when you want to put text in the EditText that the user can modify.
the correct way to do this is to use setHint(int resource) with a string resource containing your hint string.
so your onCreate should have : text1.setHint(R.String.yourhint);
and your res->values->strings.xml file should contain
<string name="yourhint">This Hint Will Disappear</string>
Use setHint(String hint) to specify the hint in an EditText.
text1.setHint("This is the hint...");
Or, in your XML layout file, you can use the attribute android:hint="This is the Hint" for the corresponding EditText.
You can use editTextExample.setHint("example") to achieve what you want.
OR, in XML, add this to your EditText: android:hint="example"
If you want to set it in xml file of the activity you can do it like this too.
in your xml file android:hint="#string/yourhint"
and your res->values->strings.xml file should contain
<string name="yourhint">This Hint Will Disappear</string>
working on an application
i need to take an EditText.
but i need as in the phone :-
The EditText already contains blurred text such as "Your Name" when you start typing the text vanishes and you text is shown. I hope you've seen this effect/property..
I'm not getting what this property is called to be searched on google...
Hint
http://developer.android.com/reference/android/widget/TextView.html#attr_android:hint
Use the following in your layout.xml file of edittext:
android:hint="Here your hint text"
I've got a TextView that I would like to allow the user to select a range of text from within it. The TextView takes up the entire width and height of the device (minus some padding and a title at the top). In an EditText if you long-click you get a selection overlay that allows you to set your selection left and right bounds. I'd like this functionality in a TextView. I've read that in API level 9 (2.3) (http://developer.android.com/sdk/android-2.3.html) there are new text selection controls, but I'm having difficulty implementing this. I'm doing this right now:
eic = new InputConnection( bookTextView );
eic.beginBatchEdit();
But it doesn't do anything noticable. Does anyone know how to use InputConnection correctly? Thanks.
Edit: I don't necessarily need to use what I was attempting above. I ultimately want to use either a TextView or an EditText which looks and feels like a TextView and be able to select text using a dragging cursor. Then I would like to manipulate the selected text with various context menu options (or a menu that pops up above the selected text).
Here is an idea.. Add an EditText with a TextView background, Here is an example
<EditText
android:text=" This is not an editable EditText"
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:textColor = "#android:color/white"
android:editable = "false"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background = "#android:drawable/dark_header">
</EditText>
add this to your xml in the place of TextView
You can enable the TextView's Spannable storage. See Highlight Text in TextView or WebView for an example.
See also:
http://developer.android.com/reference/android/text/Spanned.html
You could display the text in a WebView and enable text selection. If you want to only use a textview/edittext, here is an answer that might help you and here is information on the Spannable class that might help you accomplish what you want.
Actually, you do not have to develop this feature by yourself. You just need to use EditText instead TextView, while you set the android:editable of EditText to false. My idea is the same as sandy's.
My code is here, hope it may help you:
https://stackoverflow.com/a/11026292/966405
After long internet surfing to find a solution, i prefered create my own class
https://github.com/orionsource/SelectableTextViewer
Goal features:
Easy to use - only one class
Support for text and Html.fromHtml
Can be in ScrollView with correct touches
Cursors can be redefined
Color of selection can be redefined
All the above solutions either too long or not working for me.
What you need is to add just textView.setTextIsSelectable(true)
in your activity or fragment or adapter.
I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,
textView.setText(Html.fromHtml(someText));
Is there a way to do this through the XML?
I ask because i do not want to set the text through the code, In my case, the text comes from a DB call and displayed through an adapter.
Yes there are a bunch of (simple) tags that are understood by TextView -- if the text is set in XML from a string resource.
So basically
<TextView text="#string/foo" .. />
It is also possible to give templates like "Hello <b>%s</b>", but here you still need to run some code to fill in the value for %s
Have a look at http://developer.android.com/guide/topics/resources/string-resource.html for formatting hints and short examples.
I have an edit text and I'd like to put the following constrains (in the XML code if possible):
Disable all the capital Letters (the inverse of android:capitalize or the same fonction than toLowerCase())
Block to EditText to 1 line max. (for instance avoid that when I press enter the editText
get bigger to create a new line)
In fact , my editText is a Search Field (but in my case I don't want to use the special Search Widget).
Thanks
To make the edittext single line add this to its tag:
android:singleLine="true"
Also android:capitalize is depreciated and the following should be used instead
android:inputType="textCapCharacters"
However there seems to be no matching lowercase inputType, so you may have to implement it manually using a setOnKeyListener.
use android:lines="1" in the android xml page and then see the layout.