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" />
Related
How to make the whole TextView underline at the width of match parent like EditText?
This line of code only underlines the text, not the whole TextView.
textView.setPaintFlags(textView.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
The reason I want to use TextView is that setOnClickListener is triggered immediately in one tap for TextView, whereas two taps are required for a disabled editable EditText.
You can put the background of an EditText on your TextView. For example:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your text"
android:hint="My hint"
android:textColor="?attr/editTextColor"
android:background="?attr/editTextBackground"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
/>
You might want to change the text appearance to android:textAppearance="#style/TextAppearance.AppCompat.Button" if you are using an AppCompat theme.
You can achieve this without writing many lines of xml attributes:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your text"
android:hint="Your hint"
style="#android:style/Widget.EditText"
/>
Is there a way to change the edittext style of the Hole theme? I don't want the default padding, neither the blue/grey line underneath. I just want a plain EditText I can put in a box with a hint. Thanks!
You can use any texture you want for your EditText view. Just pick something on the web and set it as the background of your EditText.
Example:
<EditText
android:id="#+id/etlsPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/login_scr_field"
android:hint="#string/password"
android:inputType="textPassword"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/my_darker_gray" />
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 am creating a custom button. I want to set the position of text on button.
I have two background images for button (button_off and button_on) first is for normal button and second is for onFocus / onPressed state.
Now I have to put text on button then it should look like:
But i am unable to set the exact position of the text on this background button image.
Please share your suggestion to solve this issue.
You can try using 9-patch image as a background. More information on this here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
You can set these properties in XML file, `
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableLeft="#android:drawable/ic_lock_lock"
android:text="All"
android:gravity="center"/>
`
Align the text , use gravity option ! or try with padding
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/arrow_down_float"
android:background="#drawable/btn_all_bg"
android:text="All">
Button>
You can use the drawableLeft/right/top/bottom to add icon on a button and text would automatically adjust.
Few ways :
define a button and try android:drawableStart
extend Button and draw yourself
try to define a LinearLayout that hold a text and an image with a
background of your button,
set both of them weight of 1 and put them inside another LinearLayout and make them onClick
can't assure 3 will work without a tweak or two but it worth trying
You can use the layout as a button style="#android:style/Widget.Button", and configure it as you want.
Paste this in your xml file:
<LinearLayout
android:id="#+id/button"
style="#android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:text="TextView" />
</LinearLayout>
I have an EditText and a Button set next to each other on the same horizontal line. It looks great, except when the user enters a lot of text, the EditText is resized, and the Button is squished.
I have both EditText and Button set to layout_width="wrap_content". "fill_parent" messes up the layout, and I don't want to use absolute sizes if I don't have to - the way it is now looks great in both landscape and portrait, I just don't want the EditText to resize.
My layout:
<TableLayout
android:id="#+id/homelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView
android:id="#+id/labelartist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Find artists:" />
</TableRow>
<TableRow>
<EditText
android:id="#+id/entryartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:background="#android:drawable/editbox_background"
android:editable="true"
android:padding="5px"
android:singleLine="true" />
<Button
android:id="#+id/okartist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:text="Search" />
</TableRow>
</TableLayout>
For EditText use
android:layout_width="0dp" - not required but preferred.
android:layout_weight="1"
And for Button dont specify android:layout_weight
What I do is in the onCreate for the activity, measure the EditText first then apply its maxWidth.
You can do so using code similar to the following:
EditText someedittext = (EditText)findViewById(R.id.sometextview);
someedittext.setMaxWidth(someedittext.getWidth());
Give EditText a maxWidth. That should stop it from resizing beyond the width you provided. Also, if you want it to be contained within 1 line set the maxLines setting to 1 too.
You need to add android:imeOptions to prevent this behavior.
Just use:
android:layout_width="fill_parent"
for both EditText and Button. It will also work set for EditText but it is better to have it on both.
you can define size of your edittext as it shows above
android:minWidth="80dp"
android:maxWidth="80dp"
or
android:layout_width="60dp"
or
you can apply a background image of size you want
but don't forget to define its height and width
with wrap_content.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
I had a similar problem, but I couldn't get the above to work. What I did, is take in the text from EditText box and then format it down to the max size that my screen could handle. When I save this off to the DB, I will save it as display Text and original text.
If you go to this page I put a longer explanation.
The correct way to do this would be to set the android:minWidth and android:maxWidth equal to the width you want. This way you will not have to adjust your layout to use the android:layout_weight.
For example if you want your EditText to always be 80 density pixels no matter how many characters you type in use the following:
android:minWidth="80dp"
android:maxWidth="80dp"
I had the exact query. But i had an EditText and a Button next to each other in a Linear Layout.
I tried android:layout_weight="1" for EditText
android:layout_width="0dp"
And it worked just perfect!!
Thanks a lot!
The chosen solution works, but let me add a little complement:
if you use
android:layout_weight="0.15" (the value is not important)
then
android:layout_width="0dp" if the LinearLayout is Horizontal
or
android:layout_height="0dp" if the LinearLayout is Vertical.