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" />
Related
<TextView
android:id="#+id/textView6"
android:layout_width="76dp"
android:layout_height="25dp"
android:layout_marginStart="35dp"
android:gravity="center"
android:orientation="horizontal"
android:text="Password"
android:textColor="#FFFFFF"
android:textSize="18sp"/>
I can not see Password text on the phone . I can see outside how can ı fix this?
Sorry for eng.
change android:textColor value to #000000. But better to use android:hint instead of android:text. You can also change android:hint color by android:hintColor
Actually the text is there but you can't see it because your text color is the same as the background color (which is white)
So, try changing the text color or changing the background color (or use dark mode to see your text).
If you have a problem with color and you have a single theme, you can combine day and night themes. If the user's Android phone was more than 8, only one theme will work.
I think the bad part
android:layout_height="25dp"
It can be difficult to be seen in phones of different sizes
when u wanna use TextView, try this way for me it's always working.
<TextView android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center"
android:text="Password"
android:textColor="#FFFFFF"
android:textSize="12sp"/>
so how you can see u don't need
android:layout_marginStart="35dp"
android:orientation="horizontal"
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"
/>
I have taken an EditText as follows :
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is text"
android:drawableLeft="#drawable/search"
android:layout_centerInParent="true"/>
What if I want to set some spaces between that drawable icon and hint of EditText ?
For this use the attribute drawablePadding. This adds some padding between text and image.
Use android:drawablePadding property.
eg. android:drawablePadding="5dp"
Try this
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is text"
android:drawableLeft="#drawable/search"
android:layout_centerInParent="true"
android:drawablePadding="10dp" />
Add These Two Lines Of Code And you are good to go your icon will not touch the border of EditText and your icon and hint has some space in between As you can see in the pictures below
<EditText
android:drawablePadding="10dp"
android:paddingLeft="15dp"/>
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" />
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.