0

Is it possible to adjust the EditText size to match the hint size? If not, what is the best way to allow users to enter their date of birth? I have a signup form and I used an EditText for all fields and the UI would be nicer with three EditTexts for each field (DD - MM - YYYY)

Edit

In the screenshot, the last 3 fields should be for date of birth. DD - MM - YYYY In the month and year fields there is a hint but it's not shown. enter image description here

Motassem Jalal
  • 1,254
  • 1
  • 22
  • 46

3 Answers3

0

The most common and convenient way to do it is to use a date (time) picker.

enter image description here

Since it is a dialog box, you could call it from a button like this:

<Button android:layout_width="..." android:layout_height="..." android:text="Select birthdate" android:onClick="selectDate" />

and have it appear nicely adjusted to the device screen from the selectDate() method. Here are some examples: http://developer.android.com/guide/topics/ui/controls/pickers.html

user102
  • 35
  • 6
0

It has been asked already. Try this one Android EditText hint

EDIT: If you are looking for something like this https://i.stack.imgur.com/txyNd.jpg

Then this is the code:

<LinearLayout
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="horizontal">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="DD"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="-"/>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="MM"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="-"/>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="YYYY"/>

</LinearLayout>

Simple use the android:hint for mentioning the hint. Used TextView for adding the hyphen.And you can use "android:weight" to balance the distance between the text views if you want some presentable decoration in your UI.

Hope this helps.

Community
  • 1
  • 1
0

Adding a width attribute solved it.

<EditText
   android:id="@+id/input_dob_year"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:width="100dp"
   android:hint="YYYY"
   android:inputType="number"
   android:paddingRight="50dp" />
Motassem Jalal
  • 1,254
  • 1
  • 22
  • 46