Add a title or description to an EditText - android

If you open an app like gmail, and you compose a new email in the To and Subject lines, it says To and Subject in the respective EditText's. How do you add a title like that to an EditText? Are those custom views? Or is it possible to do that with the default widget?
Thanks.

It is called a hint.
Set your hint programatically or use it as xml attribute.

I think the attribute hint is what you are looking for.

Here is some sample code:
<EditText android:hint="Write Caption" />

Related

How can use Image In editText Android

How can i use above image inside of edit text Android?
You can use the "drawableLeft" attribute of EditText. For example:
android:drawableLeft="#drawable/ic_user"
http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableLeft
user this in your edittext
<EditText
...
android:drawableLeft="#drawable/my_icon" />
Another way is that you can create ImageView for that icon. This way you have more control on placing it
Add left paddding and set EditText background to your drawable:
android:paddingLeft="10dp"
android:background="#drawable/my_icon"

Edittext input type alignment extra space

I want to give extra space to input texts in my edit text.
here is what I have now :
but I want to achieve this :
which property of edittext will do this (in xml) ?
or I have to do this in another way ?
Thanks in advance !
android:paddingLeft is the property you need. You can use it as android:paddingLeft="8dp"
Checkout this answer here: https://stackoverflow.com/a/4619943/1739882
Add this attribute:
android:paddingLeft="10dp"
padding usually used to give an alignment to the text inside the EditText or even Buttons
please inform me if this is what you are looking for

Only Text in EditText on Android?

I want to only text (input) in edittext in App Android.!
example: Only type "Text: A-> Z", Not allow number or special character.?
Please give me idea, how should it be done?
Thank very much.!
Try this way,
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="text"
For more info, you may check http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits
I think you can do this by the following attribute in ur xml file.
android:inputType
for more on this see this link:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
i think you should set it like this:
android:inputType="text"
or try this:
http://www.anddev.org/view-layout-resource-problems-f27/how-to-create-edittext-allow-only-alphabets-capital-and-smal-t12236.html

EditText not wrapping its content

I am trying to create an EditText which toggles its state between read only and write mode.
My XML is as below:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="4"
android:inputType="textMultiLine">
</EditText>
In my code i do the following :
textArea = (EditText) convertView.findViewById(com.pravaa.mobile.R.id.textArea);
//isEditable decides if the EditText is editable or not
if(!isEditable){
textArea.setInputType(InputType.TYPE_NULL);
}
//the view is added to a linear layout.
addView(textArea);
My issue is that the text does not get wrapped. Am i missing out on something? Kindly help me with this. I have also attached an image of my output.
The text set in the view is "12345678901234567 90123456789012345678901234567890 Nationwide Campaign New"
I was able to solve this issue by removing
android:inputType="textMultiLine"
To achieve the non-editable feature I used
setFocusable(false);
I guess that by calling this ...
textArea.setInputType(InputType.TYPE_NULL);
you override the flag InputType.TYPE_TEXT_FLAG_MULTI_LINE. Try calling this instead...
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This line will make the text multi-line and will wrap the text
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
You'd probably also want to call setLines(n) to set the height of the textArea.
Try to replace:
editText.setInputType(InputType.TYPE_NULL);
with:
editText.setRawInputType(InputType.TYPE_NULL);
I would say that by using textArea.setInputType(InputType.TYPE_NULL); you remove the textMultiLine from your xml.
Just set textMultiLine isn't enough. Try this:
textArea.setHorizontallyScrolling(false);
textArea.setEllipsize(null);
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
What me helped was:
edtText.setInputType(InputType.TYPE_NULL);
edtText.setSingleLine(false);
It seems that the setSingleline Attribute in the XML file is ignored.

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