I am using a autocompletetextview in my app.I want to set hint in this by code.Is it possible?
Used Xml code is..
<AutoCompleteTextView
android:id="#+id/autoCompletedTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:background="#android:color/transparent"
android:singleLine="false"
android:textColor="#color/text_white"
android:textSize="#dimen/text_size12sp" />
code is........
autocompleted.setHint(getResources().getString(R.string.select_pickuplocation));
Yes it is possible and easy. Try with this...
autoCompleteTextView.setHint("Your Hint");
One way is with xml
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/passwordEntry"
android:ems="10"
android:text=""
android:hint="Test" />
Other way is programatically
autoCompleteTextView1.setHint("YourHint");
and if you want to set Text from your strings resources you can do it like this:
autoCompleteTextView1.setHint(getResources().getString(R.string.yourString));
Hope to help!
If you want to display hint at the bottom of the matching list, use setCompletionHint. If you want to use normal hint, use setHint.
Related
Are there any possibilites to utilise spinner customized designs like the below picture?
this is my spinner xml
<Spinner
android:id="#+id/service"
android:layout_width="match_parent"
android:textColor="#000"
android:layout_height="wrap_content" />
I'm interested in achieving this with Android.
First: You need an image say "spinner_bg.png", like this.
Second: Set this image as background to you spinner like this.
<Spinner
android:id="#+id/service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/spinner_bg"
android:textColor="#000" />
Hope this helps you.
I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons
i want to transparent an edittext in both Background and textColor sides. so i used this lines in my java code:
tempEditText.setTextColor(Color.TRANSPARENT);
tempEditText.setBackgroundColor(Color.TRANSPARENT);
but unfortunately this tempEditText object shows when i start typing any character on it. i want it to be completely invisible when i typing somthing to it. so i want it to be focused, get some texts, and i want the ability of retrieving strings that typed on it, but all in invisible state of edittext. i test visibility=invisible but in this situation the edittext cant give texts...
<EditText
android:id="#+id/tempEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:textColor="#00000000"
android:singleLine="true" />
any tips?
thank you...
Try:
android:background="#android:color/transparent"
or
android:background="#null"
Edit: show the virtual keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(exampleView.getWindowToken(), 0);
Change EditText background android:background="#00000000" or android:background="#null" in your xml file.
For Text Color android:textColor="#00000000" in xml file.
Try this,
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0">
or programmatically you can set alpha to your EditText
editText.setAlpha(0.0f);
Note: The issue is user will not able to see cursor!
I did this in my XML File :
android:textCursorDrawable="#null"
android:textColor="#android:color/transparent"
android:background="#null"
Make the EditText background attribute as #bb000000 for making it transparent.
If you are on Eclipse use the GUI to do it, or do this in your XML file android:background="#bb000000".
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#null"
android:id="#+id/search_input"
app:layout_constraintLeft_toRightOf="#+id/filter"
app:layout_constraintRight_toLeftOf="#+id/search_button"
/>
use this line,then it will obviously work
android:background="#null"
I need to center the Hint text within an EditText in Android. How do I do this?
In order for centering of hint text to work with EditText you have to make sure android:ellipsize="start" is defined. I don't know why this makes it work, but it does.
Example pulled from personal code:
<EditText
android:id="#+id/player2Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="start"
android:gravity="center_horizontal"
android:hint="#string/player2_name"
android:inputType="textCapWords|textPersonName"
android:singleLine="true" />
Actually, android:gravity="center_horizontal" creates the centering effect you're looking for. Similarly, you can use android:gravity="start" to put hint text at the beginning of the EditText view, and so on.
Use this xml attribute:
android:gravity="center"
use attribute
android:gravity="center"
I used this code in every circumstances, and it works perfectly without using android:ellipsize="start" to make a hint in center.
<EditText
android:id="#+id/player2Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:hint="robi"
android:inputType="text" />
I think the answer should be :
android:textAlignment="center"
textAlignment worked for me.
textAlignment="center"
Unfortunately, neither answer helped me aligning hint, written in LTR language, while the layout orientation was RTL. I needed such layout in a kind of translation application to make overlay icons not interfere with RTL text. But this trick didn't work with hints while there was no any text yet (icons appeared above the hint) and I came to the following java solution to layout problem:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
. . .
if (isRightToLeft()){
EditText guess = (EditText) rootView.findViewById(android.R.id.text1);
CharSequence hint = "\u200F" + guess.getHint();
guess.setHint(hint);
}
. . .
}
The trick was in right-to-left mark to prepend a left-to-right string. And it seems to work, but does anyone know a more elegant solution?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="ENTER PIN"
android:inputType="numberPassword" />
</android.support.design.widget.TextInputLayout>
Note: in the tag TextInputEditText,the property
android:gravity="center"
is what makes the deal of aligning the text in the center including the hint text
use this: android:gravity="center"
I use this and worked for me
android:gravity="Left|center_vertical"
use android:textAlignment="center" in EditText , it work for me
This worked for me:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nombreslayoutinput">
<EditText
android:id="#+id/nombreslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/nombres"
android:layout_centerInParent="true"
android:gravity="center|center_vertical"
android:ellipsize="start"
android:inputType="textCapWords|textPersonName"
/>
</android.support.design.widget.TextInputLayout>
The correct answer is
android:gravity="center_horizontal
hint gravity
android:textAlignment="center"
text gravity
android:gravity="left"
My problem was that the EditText wasn't big enought to fit exactly inside its parent (FrameLayout in my case), so using just android:gravity="center" (center_vertical, horizontal, start, or whatever) would just fit it inside the EditText, and not in its parent, so I had to center the EditText inside its parent using:
android:layout_gravity="center"
pd: I used android:background="#android:color/transparent" to hide the ugly underline in the EditText hint
By default my EditText has next view:
<EditText android:layout_height="wrap_content" android:paddingLeft="10dip"
android:layout_width="wrap_content" android:gravity="center_vertical"
android:inputType="textShortMessage"
android:id="#+id/search_string" android:background="#drawable/search_text_bg">
<requestFocus></requestFocus>
</EditText>
When I input text to it, it changes self size and background stretches. how to avoid it?
There are some attributes you need to set:
If you want to have single line edit text then do:
android:singleLine="true"
If you want to define maximum lines for edit text then do:
android:maxLines="3"
One simple solution is to have android:layout_width="match_parent" and android:singleLine="true"
android:layout_width="match_parent"
OR
android:layout_width="fill_parent" // deprecated
OR
android:layout_width="50dip" // Manually assign any width you want.