I am doing an app that involves getting input from the user, and so I want to be as minimalist as possible. I am looking for a way to place what should be written in a number box like this:
+----------------------------+
Enter number of days
+----------------------------+
in a grayed out manner, that dissapears when a number is placed inside.
I tried to google it, but since I couldn't find the right word (Not a native speaker), I couldn't find the right results. So I come here for help.
use android:hint="Enter number of days"
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter number of days"
android:inputType="number"
/>
See here for the "hint" usage: http://developer.android.com/reference/android/widget/TextView.html#getHint()
Related
I have edit text view in my layout like below. I am able to set digits to accept but I want set limit to accept between two numbers like 1 to 100 from java. I am not able to get idea how I can achieve this. My edittext is like below
<EditText
android:id="#+id/userInputDialog"
android:layout_marginTop="20dp"
android:layout_below="#+id/dialogueError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="120"
android:textStyle="bold"
android:digits="0123456789"
android:textColorHint="#color/toolbar_text"
android:textColor="#color/toolbar_text"
android:inputType="number" />
Let me know if anyone can help me here for same. Thanks!
You have
android:maxLength="2"
To set it to only 2 chars length.
You can also use
android:inputType="number"
For numbers only
I've made a TextInputEditText for a PasswordField with a DrawableLeft as an icon, and then i added a PasswordToggleEnabled(true) .. this operation has deleted or hiden my DrawableLeft, Here's my code:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleContentDescription="Show Password"
app:passwordToggleEnabled="true"
app:hintEnabled="false"
android:id="#+id/signupPasswordlayout"
app:passwordToggleTint="#color/edittexttint">
<android.support.design.widget.TextInputEditText
android:hint="Password"
android:id="#+id/signupPassword"
android:drawableLeft="#drawable/ic_password"
android:drawablePadding="10dp"
android:inputType="textPassword"
android:drawableTint="#color/edittexttint"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
so , is it possible to show both ( PasswordToggle and DrawableLeft ? ) thank you!
I'd not seen this exact behavior before, but looking at the source for TextInputLayout, it does attempt to preserve the user-set drawables when it applies the placeholder drawable for the password toggle. However, like most everything else in the support libraries to which its applicable, it handles them with relative positions - i.e., start and end - rather than absolute - left and right.
The support libraries have always been notorious for breaking anything that specifies absolute directions or positions, so it's no surprise that that's the issue here, as well.
Simply change the attribute you're setting to drawableStart, instead of drawableLeft. Keep this in mind, too, for anything else involving a choice of absolute or relative positions and directions with the support libraries.
In my Android App, I want to let user to type Full Name at one point to an EditText. There I need the following behaviour
1). Should NOT allow user to type invalid characters. For that I was using the following
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
2). The keyboard should have the "ActionNext" to easily move to next Field. For that I was using the following
android:imeOptions="actionNext"
But when I specify digits as above, it looses the ActionNext and instead get Enter Key (move 2nd line)...
My full xml is as follows,
<EditText
android:id="#+id/editText_FullName"
android:layout_width="300dp"
android:layout_height="40dp"
android:inputType="textCapWords"
android:maxLength="40"
android:layout_marginStart="10dp"
android:textSize="16sp"
android:typeface="normal"
android:longClickable="false"
android:lines="1"
android:scrollHorizontally="false"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:imeOptions="actionNext"/>
I found after searching in google it saying to use android:singleLine="true" to fix the issue. Yes that fix issue but this attribute is deprecated and and Android Studio suggests to use android:maxLines="1" which again NOT fix the issue and loose ActionNext in Keyboard. Basically instead of ActionNext I still see Enter key (move next line) option.
Has anyone got a solution for this. Thanks
Edits
I could use regular expression validation or register the EditText to a KeyListener. But looking for a pure xml solution.
I have a standard straight forward EditText, I want to show the dictionary suggestions on top of this EditText so I did this in the XML:
<EditText
android:id="#+id/messaging_messageEdit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="85"
android:background="#drawable/clanz_edit_text_holo_dark"
android:ems="10"
android:hint="Type your message here..."
android:singleLine="true"
android:inputType="textAutoComplete"
android:textColor="#dedede" >
</EditText>
I thought that the inputType parameter would take care of the auto dictionary view. On my phone (Nexus Android 5.1) the dictionary view appears but is blank. On a Genymotion emulator (Android 4.1.1) it does not display at all.
What am I missing?
This can be one solutions if you are looking for AutoComplete TextView.
<AutoCompleteTextView
android:id="#+id/from_station"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/enter_start"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:textColorHint="#color/transparent_black" />
You can also set threshold value using paramters.
Need to set adapter values at runtime.
If I understand correctly you want the keyboard to have auto correction right?
According to the Android developers website:
Can be combined with text and its variations to specify that this
field will be doing its own auto-completion and talking with the input
method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE.
This is not what you're looking for. You are probably looking for textAutoCorrect which is this according to the Android developers website:
Can be combined with text and its variations to request
auto-correction of text being input. Corresponds to
TYPE_TEXT_FLAG_AUTO_CORRECT.
I've made a lot of apps and never used one of those though. It just auto corrects if you have a normal EditText.
I had the same problem not getting keyboard suggestions on some of my EditText views. Please pay attention there is a difference between autoComplete text views and getting keyboard suggestions while typing! They happen in two different places, first one inside the AutoCompleteTextView the other one on top of your keyboard while typing.. (for example you type te => it suggests "tea teaspoon teapot" to make your life easier.)
To achieve that I had to turn off the input types that I was setting programmatically and when you do so, the default behavior is back and that means getting keyboard word suggestions:
// etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
I tried the following but I still did not get a keyboard suggestions:
etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
at the end I commented all the above and it worked just fine!
here I also found that someone else had the reverse problem meaning they wanted to disable this functionality and they suggested to use the code that I had commented! read here
(we all know) There are three parts in android Switch Widget ... Text - Thumb - Track.
My question is how can we completely remove this text part if we don't want to use any text
because it's ruining the balance of the layout
You simply have to not provide any text:
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Use negative margin for the switch as follows and see if it works:
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-10dp" />
I know some people consider it a bad practice to use negative margin but right it seems to be the easiest way.
You can set margin programmatically as well based on device type.