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.
Related
I have used the android:digits in editText view to accept only letters, but when i set this property then single line restrict is not working.
It always creates new line when i enter more text.
If i remove the digits property, single line restrict works.
android:inputType="text"
android:maxLines="1"
android:digits="abcdefghijklmnopqrstuvwxyz"
android:singleLine="true"
will work for you. But since it is deprecated it is not advisable to use it.
But it is the easiest solution for it.
I downloaded a code and the source is written in this format:
<android.support.design.widget.TextInputEditText/>
instead of:
<EditText/>
I tested both of them and i didn't see the difference, so I want to know if there's a difference between these two ways of declaring a widget in Android.
<android.support.design.widget.TextInputEditText/>
Creates a Field with an EditText with more functions like show the placeholder up the edit text when you're typing in.
https://gyazo.com/844d6c0fe8aace1ef671859823d39a58
https://gyazo.com/bf891de7807955e76bf487e3a07a6317
Only difference is: in landscape mode you can see the hint in TextInputEditText1, whereas you can't see in EditText.
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>
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.
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).