Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the style of TextInputEditText in styles.xml

Tags:

android

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.

like image 519
N Sharma Avatar asked Oct 07 '17 18:10

N Sharma


People also ask

How do I set TextInputLayout style programmatically?

Method 1 - Create TextInputLayout programmatically with wrapping Context with android. view. ContextThemeWrapper and use. TextInputLayout layout = new TextInputLayout(new ContextThemeWrapper(getContext(), R.

How do I change the style of edit text in Android Studio?

You can use the attribute style="@style/your_style" that is defined for any widget. The attribute parent="@android:style/Widget. EditText" is important because it will ensure that the style being defined extends the basic Android EditText style, thus only properties different from the default style need to be defined.


1 Answers

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.

like image 61
Rafael Chagas Avatar answered Oct 24 '22 13:10

Rafael Chagas