Material-components-android: [TextInputEditText] Several issues with typefaces in TextInputEditText (e.g.,Typeface is not applied with textPassword inputType)

Created on 10 Sep 2019  路  10Comments  路  Source: material-components/material-components-android

Description:
Typeface is not applied with textPassword inputType.

Expected behavior:
When android:inputType="text|textPassword|textNoSuggestions" (incorrect behaviour)
Screenshot_1568119309

When android:inputType="text|textNoSuggestions" (expected behaviour)
Screenshot_1568119497

Source code:

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/passwordInputAlphanumeric"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_padding_size_medium"
            android:theme="@style/Widget.App.TextInputLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/passwordAlphanumeric"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/login_hint_password"
                android:imeOptions="actionDone"
                android:inputType="text|textPassword|textNoSuggestions"
                android:maxLines="1"
                tools:ignore="Autofill,LabelFor"
                tools:text="11223344"
                />
        </com.google.android.material.textfield.TextInputLayout>


<style name="Base.TextAppearance" parent="@style/TextAppearance.AppCompat">
    <item name="android:fontFamily">@font/ubuntu_regular</item>
    <item name="fontFamily">@font/ubuntu_regular</item>
</style>

Android API version:
All

Material Library version:
1.0.0

Device:
Emulators

bug

Most helpful comment

Also related:
When I try to set a font family in HintTextAppearance. It doesnt work.
Is there any reason?

 <style name="hintStyle" parent="TextAppearance.Design.Hint">
        <item name="android:fontFamily">@font/xyz</item>
        <item name="android:textColor">@android:color/holo_red_dark</item>
        <item name="android:textSize">12sp</item>
    </style>

* Material Library version:* Material Android Library version 1.1.0-alpha10

All 10 comments

Also related:
When I try to set a font family in HintTextAppearance. It doesnt work.
Is there any reason?

 <style name="hintStyle" parent="TextAppearance.Design.Hint">
        <item name="android:fontFamily">@font/xyz</item>
        <item name="android:textColor">@android:color/holo_red_dark</item>
        <item name="android:textSize">12sp</item>
    </style>

* Material Library version:* Material Android Library version 1.1.0-alpha10

Also:

HintTextAppearance with textAllCaps doesn't work #586

Also related:
When I try to set a font family in HintTextAppearance. It doesnt work.
Is there any reason?

 <style name="hintStyle" parent="TextAppearance.Design.Hint">
        <item name="android:fontFamily">@font/xyz</item>
        <item name="android:textColor">@android:color/holo_red_dark</item>
        <item name="android:textSize">12sp</item>
    </style>

* Material Library version:* Material Android Library version 1.1.0-alpha10

also not working in 1.1.0-beta02

Jesus christ this library is a steaming pile of shit. Nothing is working.

The same bug. Any news when this will be fixed?

Seems like the fontFamily of the inner TextInputEditText is also applied to the hint, even when the outer TextInputLayout sets it to something else using hintTextAppearance.

If you write a custom typeface override to reuse all over the project programatically, it doesn't render correctly

class FontOverrideEditText @JvmOverloads constructor(
  context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextInputEditText(context, attrs, defStyleAttr) {

  init {
    typeface = ResourcesCompat.getFont(context, R.font.your_font)
  }

}

Is an issue on (current latest) 1.3.0-alpha01 still.

At this time, we can't use TextInputLayout because of the issue pointed out in #586 specifically. Use requires a series of focus, error, and text change listeners to determine the appearance of the TextInputLayout hint text.

Looks like hintTextAppearance doesn't work because it's always overridden by the inner edit text text style. Is it expected behavior, or it's something that will be fixed?
image

A temporary workaround can be setting hint text appearance after the view layout
textInputFieldView.doOnLayout { textInputFieldView.setHintTextAppearance(R.style.TextInputFieldHintTextAppearance) }

Was this page helpful?
0 / 5 - 0 ratings