How to place a frame or space between Edittext’s?

Asked

Viewed 3,482 times

1

I have 3 EditText's in a layout that are distributed the weights between them, but when I go down with a color, the impression that it is only one, would have a better editing method or put a margin?

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <EditText
            android:id="@+id/M00"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000ff"
            android:ems="10"
            android:gravity="center"
            android:inputType="numberSigned|numberDecimal"
            android:textColor="#ffffff" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/M01"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000ff"
            android:ems="10"
            android:gravity="center"
            android:inputType="numberSigned|numberDecimal"
            android:textColor="#ffffff" />

        <EditText
            android:id="@+id/M02"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000ff"
            android:ems="10"
            android:gravity="center"
            android:inputType="numberSigned|numberDecimal"
            android:textColor="#ffffff" />
</LinearLayout>
  • Well, the margin you can use the parameter android:layout_margin, and when you say "frame", you are referring to a border in these text fields?

  • Yes, that’s exactly it

  • @Paulorodrigues android:layou_margin would solve, but gave error when putting in Edittext

  • You used layou_margin even without the t, or was just typo here?

1 answer

1


On the margin, as I commented, you can use the parameter android:layout_margin in each of its EditTexts, for example:

android:layout_margin="3dp"

This includes margin in the four corners, but if you prefer you can only include left or right, where necessary, with layout_marginRight or layout_marginLeft. Remembering that this will also require the parameters layout_marginStart and layout_marginEnd.

For the edges, you need to create a file inside the directory res/drawable that will represent the background of EditText. I named it after edittext_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#0000ff"/>
    <stroke android:width="1dp" android:color="#ffffff"/>
    <corners android:radius="3dp"/>
</shape>

In this example, the text box will stay with the blue background (#0000ff), white border (#ffffff) and rounded (3dp). This is a basic implementation, but you can increment even more as for example change when having focus and etc.

And then just change the background of EditText:

android:background="@drawable/edittext_bg"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.