4

I want to set custom font size of hint of TextInputEditText. I have an style which I want to apply to my all TextInputEditText.

It is not applying on my TextInputEditText. Can anyone help me where I am missing something ?

styles.xml

<resources>

    <!-- Base application 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>
    </style>

    <style name="Widget.Design.TextInputLayout" parent="AppTheme">
        <item name="hintTextAppearance">@style/AppTheme.TextFloatLabelAppearance</item>
    </style>

    <style name="AppTheme.TextFloatLabelAppearance" parent="TextAppearance.Design.Hint">
        <item name="android:textSize">18sp</item>
    </style>

</resources>

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".login.AuthenticationActivity"
        android:label="@string/login_screen_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

layout.xml

<android.support.design.widget.TextInputLayout
    android:id="@+id/access_code_input_layout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="@+id/guideline"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@+id/guideline">

    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/login_participation_access_code"
        android:inputType="textPassword" />

</android.support.design.widget.TextInputLayout>
azizbekian
  • 60,783
  • 13
  • 169
  • 249
N Sharma
  • 33,489
  • 95
  • 256
  • 444

1 Answers1

4

You can either directly apply app:hintTextAppearance to TextInputLayout:

<android.support.design.widget.TextInputLayout
    ...
    app:hintTextAppearance="@style/AppTheme.TextFloatLabelAppearance"
    ...
    >

Or change your activity's or application's theme in AndroidManifest.xml:

android:theme="@style/Widget.Design.TextInputLayout"
azizbekian
  • 60,783
  • 13
  • 169
  • 249
  • I can not set my application/activity them `android:theme="@style/Widget.Design.TextInputLayout"`. Can we add this in item of AppTheme ? If so then how ? – N Sharma Mar 31 '17 at 17:19
  • `Can we add this in item of AppTheme?` What do you mean? – azizbekian Mar 31 '17 at 17:20
  • Like this `@color/colorAccent` – N Sharma Mar 31 '17 at 17:21
  • Your `Widget.Design.TextInputLayout` theme does exactly what you say: it overrides `hintTextAppearance`. – azizbekian Mar 31 '17 at 17:24
  • Ahh I see. I made this change https://pastebin.com/km2V8si3 it is still not working – N Sharma Mar 31 '17 at 17:29
  • @Williams, you are missing [the concept of inheritance](https://developer.android.com/guide/topics/ui/themes.html#Inheritance) for themes. – azizbekian Mar 31 '17 at 17:30
  • I set `AppTheme` on my application like `` – N Sharma Mar 31 '17 at 17:30
  • When you are declaring a new theme and overriding a value in it, you have to apply exactly that theme to your activity. But you are applying `AppTheme`, no change will happen. – azizbekian Mar 31 '17 at 17:32
  • @Williams, given the code you have posted in your question, if you apply suggestions in my answer you will succeed. I.e., make your activity's theme be `android:theme="@style/Widget.Design.TextInputLayout"` – azizbekian Mar 31 '17 at 17:35
  • Yup. It made changes in the font size of float label not the hint of `TextInputEditText`. I am looking to change font size of hint of TextInputEditText – N Sharma Mar 31 '17 at 17:36
  • Because the initial text is not `TextInputEditText`, it's the `TextView` inside `TextInputEditText`. Apply appropriate style to `TextView`. – azizbekian Mar 31 '17 at 17:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139616/discussion-between-williams-and-azizbekian). – N Sharma Mar 31 '17 at 17:38