Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Holo theme - different text size in EditText and Spinner

I have a problem with text sizes of EditText and Spinner with the default light Holo theme. For some reason, they are not the same by default.

Suppose I have this sample layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

    <EditText
        style="@android:style/Widget.Holo.Light.Spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="EditText spinner style" />

    <Spinner
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@android:array/imProtocols" />
</LinearLayout>

... which results in this:

From the screenshot you can see that:

  1. The text size in the Spinner (3) is by default a bit smaller than in the EditText (1).
  2. If I apply Spinner style to an EditText (2), then it's font has the same "smaller" size as the Spinner.
  3. The Spinner-styled EditText also doesn't have any left padding for some reason.

What I want to achieve

I have created a custom date-time-picker component that derives from RelativeLayout and contains two EditTexts. Upon clicking, the first one displays a date-picker dialog and the second one displays a time-picker dialog.

Now, I would like to style these two EditTexts to like like a Spinner, in a similar fashion to ICS Google Calendar, which looks like this:

The second line is an EditText for the Location of the event. I have entered the same date value into it as in the From input, which is some type of View (probably also an EditText) that displays a DatePickerDialog upon click.

As you can see, the text sizes in the From and To inputs are the same as in the location EditText and also the left padding is the same.

How can I achieve a Spinner-like appearance for an EditText while maintaining the same font size and left-padding?

Where (in the android style XML files) can I find what are the actual default values of textSize, padding etc. of various views and widgets (EditText and Spinner in this case)?

like image 951
Natix Avatar asked Nov 23 '12 15:11

Natix


2 Answers

Well, since nobody else answered, this is what I have done:

I've applied the trial and error method to determine the actual text size and left padding of the EditText and then manually set these parameters:

<style name="PickerEditText" parent="@android:style/Widget.Holo.Light.Spinner">
    <item name="android:paddingLeft">12dp</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
</style>

It's a dirty solution, but it seems to work even for different text size settings in the system, so for now I'm sticking with it.

like image 191
Natix Avatar answered Nov 07 '22 13:11

Natix


https://github.com/android/platform_packages_apps_contacts/blob/master/res/layout/date_picker.xml

Above link is exactly how they do it. Very similar to the accepted answer. I would even go a different route than they did in the actual app, more like the accepted answer.

like image 1
Brentley Jones Avatar answered Nov 07 '22 12:11

Brentley Jones