how to set floating label text size?
Solution 1
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.
Solution 2
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" />
Solution 3
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 !
Parissa Kalaee
I love coding, I am professional at C/C++ and Java for Android and know well how to code C#, especially for .NET :) Recently I started to code in Kotlin, Python and JavaScript :)
Updated on July 22, 2022Comments
-
Parissa Kalaee almost 2 years
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?
-
N J about 8 yearsRead OP's question carefully he/she needs to set floating label size
-
Rahul about 8 yearsTextInputLayout is used for floating label @NJ . That is why I put this solution. Hopefully, it will helpful !
-
Parissa Kalaee about 8 yearsthank you Rahul, I used that before asking the question, but unfortunately the same as I asked in the main question, it just make changes to size of hint text and input text, I want to change floating label text size, when it gets small and moves to the top of editText.
-
Parissa Kalaee about 8 yearsthank you very much :) you really saved my day :) I somehow used your answer to reach my goal, but your answer lighten the true way :) I will add my answer below for others :)
-
Bajrang Hudda over 6 yearsWhat if I want style only for hint not for real text that is in Edittext.
-
Bajrang Hudda over 6 yearsSize and color works fine but if I am trying to change text style... nothing change.
-
Parissa Kalaee over 6 years@BajrangHudda in what way do you want to change style? give me an example. since size and color are also parts of style :-)
-
Weiyi about 5 years@par4301how about <item name="android:textStyle">bold</item>? which doesn't work
-
OneWorld over 4 yearsIs
style=@style/CustomEditText
part of the solution? If yes: Pls post the style. If not: Remove it in order to provide a clearer answer.