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"
Related
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.
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
I want to have a Button or a clickable View in my EditText so that I can perform some action on click of it. I was able to put a drawable inside my EditText thanks to Marcosbeirigo for this answer. But, now I want to make it clickable so that I can perform some action on it. I know this is possible as HTC uses buttons inside EditText in their stock sms app as shown in the following image-
In my case, the button will be positioned anywhere, can be in the center also. But the main thing is how can I put a button in EditText?
Use RelativeLayout. The Send and Attach buttons are simple Android Buttons and the 32/160 is a TextView. Put the buttons and the textview on the EditText object, play with the layout arrangments and set some right padding to the EditText object so that the text inside it won't go under the buttons.
You don't need any drawable and listening to the click event of the android buttons is not a question anymore.
Its absolutely correct
Use this , It worked for me -
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/id_search_EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:paddingRight="40dp"
android:hint="Enter your feelings and connect" />
<ImageButton android:id="#+id/id_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/id_search_EditText"
android:layout_alignBottom="#+id/id_search_EditText"
android:layout_alignRight="#+id/id_search_EditText"
android:background="#drawable/ic_launcher"/>
</RelativeLayout>
I think you try to search set click event for compound drawable. You can find some solutions here
handling-click-events-on-a-drawable-within-an-edittext
there is no button inside editText It's just an editText with white background so you don't see it's margins and a simple layout arrangement.
The only possible solution is to use a RelativeLayout that allow you to put also Views in overlay to others. Other Layout wont allow you to do such things.
Also I found this tutorial: http://developer.android.com/resources/articles/layout-tricks-merge.html maybe it can helps you :)
Use this this code may work.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/REFReLayTellFriend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editext_rounded"
android:drawableLeft="#android:drawable/ic_menu_search"
android:gravity="start"
android:hint="Search"
android:singleLine="true"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtSearch"
android:background="#drawable/ic_action_content_filter_list"/>
</RelativeLayout>
</LinearLayout>
I wanna make the editText to look like this:
what else should I do after I set the editText's background how can I make the text start inside the edittext via code.
Are you trying to get the EditText to say "Username" by default, but not have that be the actual text?
For that you can use EditText.setHint() (inherited from TextView) or in the xml definition use android:hint, such as
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Username" />
To make text look like that, set the Gravity attribute to left. The gravity of EditText element.
As well as setting the background of the EditText view, set left and right padding, e.g.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp" />
How to make an EditText look like a TextView that is done in Java but not in XML..
I have seen how to do it using xml file like
style="#android:style/Widget.TextView"
android:editable="false"
android:cursorVisible="false"
android:longClickable="false"
but i want this to be done in java because i am not using any xml file for the layout..
everything is done in code itself ..
I am trying to use GestureListener in my code .. it worked fine for TextView but not EditText
So, anything to do for the EditText so that the GestureEvents can be implemented ?
Thanks,
EditText Et; // initialize your edittext//
Et.setCursorVisible(false);
Et.setLongClickable(false);
Et.setClickable(false);
Et.setFocusable(false);
Et.setSelected(false);
Et.setKeyListener(null);
Et.setBackgroundResource(android.R.color.transparent);
And you'll never see it like an EditText again.
add below two line into your edittext xml:
android:focusable="false"
android:inputType="none"
EditText is a subclass of TextView - so except for editing, what applies to TextView applies to EditText as well.
Make EditText behave as a TextView in code
try this
android:longClickable="false"
android:clickable="false"
android:cursorVisible="false"
android:editable="false"
Well I know this was a very old question, but I have to do this one of my apps and came up with a simple approach deduced from all the answers from Google/stack overflow. Suppose u want to make a edit text look like a text view and on button click make it editable, the procedure is as follows:
In your layout, set:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_postContent"
android:textSize="17sp"
android:gravity="top|left"
android:text="This is a dummy text "
android:layout_below="#+id/img_empimage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:enabled="false"
android:background="#android:color/transparent"
style="?android:attr/textViewStyle" />
And in your .java set the color of the text by:
yourEditText.setTextColor(Color.parseColor("#000000"));
before entering the onClick of button. And in the onClick of button:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(postContent, InputMethodManager.SHOW_IMPLICIT);//shows keyboard
int position = postContent.length();
Editable text = postContent.getText();
yourEditText.setBackground(getResources().getDrawable(R.drawable.border));//shows a border around your text view making it look like a edit text
yourEditTex.setEnabled(true);//enables the edit text which we disabled in layout file
yourEditTex.setCursorVisible(true);
Selection.setSelection(text,position-1);`//places the cursor at the end of the text
Now to make the edit text show again as a textView, on the onClick of another button:
String s = postContent.getText().toString();
yourEditText.setText(s);
yourEditText.setEnabled(false);
yourEditText.setTextColor(Color.parseColor("#000000"));
yourEditText.setBackground(null);`
My answer covers two or three questions combined, but I hope it'll be helpful.
This is perfect way to make EditText as TextView.
Use in your EditText.
<EditText
android:id="#+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:enabled="false"
android:focusable="false"
android:clickable="false"
android:longClickable="false"
android:inputType="none"/>
Just add an border to EditText :
First Of all add an border.xml in Resources/Drawable
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#000000"/>
</shape>
Second step :
add android:background="#drawable/border" to TextView
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="date"
android:layout_column="1"
android:id="#+id/dateFromTextView"
android:layout_marginRight="3dp"
android:background="#drawable/border"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"
android:gravity="center" />
Make EditText behave as a TextView in code
try this
In your layout, set:
<EditText
android:id="#+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:inputType="none"
android:imeOptions="actionDone"
android:enabled="false"
style="?android:attr/textViewStyle" />
This was all I needed to create the effect.
In code:
ET.setFocusable(false);
And in layout:
android:background="#android:color/transparent"
Setting the background in the layout completely removes the under bar, as apposed to just hiding it in code.
Make it editable again with:
ET.setFocusableInTouchMode(true);