androidkotlinandroid-studiohinttextinputlayout

set font for the hint TextInputLayout in Kotlin Android Studio


I work with Kotlin and android studio

        <com.google.android.material.textfield.TextInputLayout
            android:hint="شماره تلفن همراه"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
            android:layout_marginStart="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginTop="5dp"
            app:shapeAppearanceOverlay="@style/button4"
            app:boxStrokeColor="#4E4A4A"
            app:boxStrokeWidth="1dp"
            app:prefixText="+98"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:id="@+id/phoneNumber"
                android:ems="10"
                android:textSize="13sp"
                android:textColor="@color/black"
                android:textStyle="normal"
                />
        </com.google.android.material.textfield.TextInputLayout>

enter image description here

I want to set a font for the hint (شماره تلفن) and I have a font in res/font ; how can I set that font?


Solution

  • Super easy.

    In the XML of your TextInputEditText add android:fontFamily="font-family".

    <com.google.android.material.textfield.TextInputLayout
            android:hint="شماره تلفن همراه"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
            android:layout_marginStart="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginTop="5dp"
            app:shapeAppearanceOverlay="@style/button4"
            app:boxStrokeColor="#4E4A4A"
            app:boxStrokeWidth="1dp"
            app:prefixText="+98"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:id="@+id/phoneNumber"
                android:ems="10"
                android:fontFamily="YOUR FONT NAME HERE" <--- THIS
                android:textSize="13sp"
                android:textColor="@color/black"
                android:textStyle="normal"
                />
        </com.google.android.material.textfield.TextInputLayout>
    

    If this doesn't help, please let me know and I'll provide more support, happy coding!