Android: Custom EditText layout with XML - android

I am trying to customize the look of an EditText but I am failing to do so... I would like to have the textfield in rounded borders with a graphic icon to the left (so the icon would be inside the borders too, next to the edittext). Could somebody please explain me how I could achieve this? Do I need to draw the border as a shape or is there some property for this? Thanks a lot!

Try like this
<EditText
android:id="#+id/rLastName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/editbox"
android:hint="#string/lname"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="14dip"
android:drawableLeft="#drawable/ic_launcher" />
Drawable left the icon will be set in left side
You can try this link for rounded corners link

How to create EditText with rounded corners?
And
http://alinberce.wordpress.com/2012/02/20/android-edittext-with-custom-font-and-clear-button/

Related

How to set drawable with text in button android

I am trying to set drawable in my button but its not showing properly. Here is what I want to achieve
but I am unable to get the required results.
This is what I am doing
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnShareStore"
style="#style/yellowButton"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:layout_weight="1"
android:drawableStart="#drawable/ic_vector_share"
android:text="#string/lbl_share_store"
android:layout_marginStart="#dimen/margin_large"
android:layout_marginEnd="#dimen/margin_small"/>
and this is how it looks like
How can I move drawable to the adjacent left side of text?
Any help will be highly appreciated
You can try with this, keep in mind that it will need your app theme to be a descendant of MaterialTheme.
<com.google.android.material.button.MaterialButton
app:icon="#drawable/icon_search"
android:text="Hello"
app:iconGravity="textStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Android Button widget hyphenation

I have a problem with my project. I use android.widget.Button. When word can not fit in one line in the Button then it cut it like this: Somelon>gword (where '>' is new line). How to fix it? And how to create inner padding for the text because the long word touches the button's borders?
You can try below code. Where paddingRight and paddingLeft keep padding of 25dp in right and left. If you want to text on in one line.Then
you can use android:singleLine="true"
<Button
android:id="#+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:ellipsize=”marquee”
android:text="#string/im_sorry_lol_str" />
Read this post
Try using the property android:singleLine="true" and android:padding="10dp" to your button widget.

Set starting point of Edittext

I've got an EditText with my own style. Basically it's a border for the EditText. The problem is that the text starts over this border so it's not very nice. Is there a way of set the starting point of the text in an EditText?
give padding at starting side in layout like this
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...
android:paddingLeft="10dp"
/>

Split button text into two sections

I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>

What controls the default padding between views?

When I put a view on a layout, it automatically has some padding/margin on it.
See this picture:
The red rectangle show the space that the button takes. Note the empty space between the button and the red lines. That's the space in question.
What controls that space and how to I change it ?
It's messing up my lisview's button alignments!
The code for that layout:
<Button
android:text="#+id/Button01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="#+id/Button02"
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
The button has a default background set by Android. If you look at Android source code, you can find that the button's background has a transparent area around it. This is done in order to make it into a nine-patch drawable. So you cannot remove that padding unless you specify your own background drawable for the button.

Categories

Resources