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:
Spinner
(3) is by default a bit smaller than in the EditText
(1).Spinner
style to an EditText
(2), then it's font has the same "smaller" size as the Spinner.Spinner
-styled EditText
also doesn't have any left padding for some reason.I have created a custom date-time-picker component that derives from RelativeLayout
and contains two EditText
s. 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 EditText
s 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)?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With