11

I am using TextInputEditText in my registration screen. I am able to set the style of floating label. I want to set the custom font on hint and text of TextInputEditText using style. Does anyone know whats way of it ?

   <android.support.design.widget.TextInputLayout
        android:id="@+id/til_registration_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:paddingEnd="@dimen/default_view_padding_right_8dp"
        android:paddingStart="@dimen/default_view_padding_left_8dp"
        android:textColorHint="@color/colorSecondaryText"
        app:hintTextAppearance="@style/AppTheme.InputLayoutStyle"
        app:layout_constraintTop_toBottomOf="@id/textview_registration_title">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/registration_name"
            android:imeOptions="actionNext"
            android:singleLine="true"
            android:textColor="@color/colorPrimaryText" />
    </android.support.design.widget.TextInputLayout>

styles.xml

<style name="AppTheme.InputLayoutStyle" parent="TextAppearance.AppCompat">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="fontFamily">@font/lato_light</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:textViewStyle">@style/AppTheme.TextView</item>
    <item name="buttonStyle">@style/AppTheme.Button</item>
</style>

I want to set style for entire application.

N Sharma
  • 33,489
  • 95
  • 256
  • 444

1 Answers1

22

Old question but worth to answer.

Just set the "textInputStyle" to style the TextInputLayouts and "editTextStyle" to style the TextInputEditTexts in your app theme.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:textViewStyle">@style/AppTheme.TextView</item>
    <item name="buttonStyle">@style/AppTheme.Button</item>
    <item name="textInputStyle">
        @style/MyCustomTextInputStyle
    </item>
    <item name="editTextStyle">
        @style/MyCustomEditTextStyle
    </item>
</style>

<style name="MyCustomTextInputStyle" parent="Widget.Design.TextInputLayout">
    <item name="android:textColorHint">@color/colorSecondaryText</item>
    <item name="hintTextAppearance">@style/any_style_you_may_want"</item>
</style>

<style name="MyCustomEditTextStyle" parent="Widget.AppCompat.EditText">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="fontFamily">@font/lato_light</item>
</style>

This will apply the same style to all TextInputLayout and TextInputEditText in you application.

flaky
  • 6,816
  • 4
  • 29
  • 46
Rafael Chagas
  • 774
  • 7
  • 13
  • 2
    Thanks, that helped me. How does one know that 'textInputStyle' etc. exist and what they are meant for? – Ridcully Sep 27 '18 at 15:43
  • and if you want to apply customized style to just one specific TextInputEditText, what you do is add `style="@style/MyCustomTextInputStyle"` to the `TextInputLayout` – Someone Somewhere Jul 22 '19 at 21:07