Home » Android » android – how to set floating label text size?

android – how to set floating label text size?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I would like to change floating label text size in Android material EditText, when I set as follows:

<android.support.v7.widget.AppCompatEditText
    android:id="@+id/edt_current"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/str_current"
    android:inputType="number"
    android:singleLine="true"
    android:textSize="20sp" />

It just changes the text size for hint and input Text.

Since, Floating Label Text Size seems too small in my UI, I would like to change it, any solution?

How to&Answers:

Try following code. This may help you:

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse">

You may use app:hintTextAppearance="@style/TextAppearance.AppCompat.Small.Inverse" instead.

Answer:

The accepted answer helped me a lot to find my solution (i.e. setting the exact font size, not only using small, medium, …).

In addition, by defining a style for app:hintTextAppearance, you can also simply set the color of floating label 🙂

in styles.xml:

<style name="CustomTextAppearance" parent="@android:style/TextAppearance">
    <item name="android:textSize">16sp</item>
    <item name="android:textColor">@color/colorAccent</item>
</style>

and in your TextInputLayout:

<android.support.design.widget.TextInputLayout
android:id="@+id/lyt_goal"
style="@style/CustomTextInput"
app:hintTextAppearance="@style/CustomTextAppearance">

<android.support.v7.widget.AppCompatEditText
    android:id="@+id/edt_goal"
    android:hint="@string/str_goal" />

Answer:

Try The Below Code It Works In Normal State

 <android.support.design.widget.TextInputLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:theme="@style/TextLabel">

     <android.support.v7.widget.AppCompatEditText
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:hint="Hiiiii"
         android:id="@+id/edit_id"/>

 </android.support.design.widget.TextInputLayout>

In Styles Folder TextLabel Code

 <style name="TextLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">@color/Color Name</item> 
    <item name="android:textSize">20sp</item>
    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@color/Color Name</item>
    <item name="colorControlNormal">@color/Color Name</item>
    <item name="colorControlActivated">@color/Color Name</item>
 </style>

Set To Main Theme of App,It Works Only Highlight State Only

 <item name="colorAccent">@color/Color Name</item>

Hope this will help you !