How to change the hint size of TextInputLayout

50,785

Solution 1

In your styles.xml

<style name="TextLabel" parent="TextAppearance.Design.Hint">
    <item name="android:textSize">16sp</item>
</style>

And then in your layout file:

<android.support.design.widget.TextInputLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="@dimen/activity_horizontal_margin"
         android:layout_marginRight="@dimen/activity_horizontal_margin"
         android:layout_marginTop="12dp"
         app:hintTextAppearance="@style/TextLabel"
         android:minHeight="30dp">

Solution 2

Change the TextInputLayout's app:errorTextAppearance in XML.

<android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:errorTextAppearance="@style/CustomTextInputLayoutStyle.ErrorTextStyle">

Where CustomTextInputLayoutStyle.ErrorTextStyle is defined in styles.xml as

<style name="CustomTextInputLayoutStyle.ErrorTextStyle" parent="TextAppearance.Design.Error">
        <item name="android:textSize">10sp</item>
</style>

Solution 3

@Santiago Martínez answer only works for hints on non empty Edittext (inside TextInputLayout)

But for empty Edittext, TextInputLayout hint takes property from Edittext textSize.

Solution 4

1) Add hintTextAppearance to your InputLayout with a style

<android.support.design.widget.TextInputLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"     
    android:layout_height="wrap_content"
    app:hintTextAppearance="@style/TextInputLayoutHintText" >
    <android.support.design.widget.TextInputEditText            
        android:layout_width="match_parent"              
        android:layout_height="wrap_content"
        android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>

2) Then just add the style to your styles.xml

<style name="TextInputLayoutHintText">
   <item name="android:textColor">@color/gray</item>
   <item name="android:textSize">12sp</item></style>

Solution 5

For material 1.4.0

implementation 'com.google.android.material:material:1.4.0'

You only need to change the android:textSize attribute for the TextInputEditText for the hint size to change.

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"/>

    </com.google.android.material.textfield.TextInputLayout>
Share:
50,785
Ara Badalyan
Author by

Ara Badalyan

Updated on November 03, 2021

Comments

  • Ara Badalyan
    Ara Badalyan over 2 years

    This is my xml

    <android.support.design.widget.TextInputLayout
                    style="@style/main_input_text"
                    android:layout_marginTop="@dimen/activity_medium_margin"
                    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
    
                    <android.support.v7.widget.AppCompatEditText
                        style="@style/main_edit_text"
                        android:inputType="text" />
    
    </android.support.design.widget.TextInputLayout>
    

    And this is style

    <style name="main_input_text">
            <item name="android:layout_width">match_parent</item>
            <item name="android:layout_height">@dimen/activity_edittext_height</item>
            <item name="android:background">@drawable/mc_shape_border_button_transparent</item>
            <item name="android:gravity">center_vertical</item>
            <item name="android:paddingTop">@dimen/activity_extra_small_margin</item>
            <item name="android:paddingBottom">@dimen/activity_extra_small_margin</item>
            <item name="android:keyTextSize">8sp</item>
            <item name="android:textSize">8sp</item>
    </style>
    

    I don't find something like hintSize, textSize and keyTextSize not helping

  • Ara Badalyan
    Ara Badalyan over 8 years
    The problem is that i whant to make edit text size biger and hint smaller.
  • eugeneek
    eugeneek almost 7 years
    Anyway it is not worked. Hint size only increased in EditText, not in TextInputLayout.
  • Neeraj Bagra
    Neeraj Bagra over 5 years
    This style not working when there is no text in edittext (inside TextInputLayout).
  • Kirill Starostin
    Kirill Starostin almost 5 years
    @NeerajBagra It seems that hint's color in an unfocused style must be set by the android:textColorHint attribute