I want to change the font of my chronometer in android.I have set my default font to be a custom font . The font seems to be applied every where except the chronometer. I have also tried setting android:fontFamily="@font/myfont"
but it didn't work. Though the font appears to be applied in the preview window, but it doesn't change when i run my app on my device.
Any idea to get over it ?
Here's my code:
<Chronometer
android:fontFamily="@font/linotte_semibold"
android:id="@+id/audio_player_chronometer"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@+id/frame_layout"
android:textColor="@color/white"
android:layout_margin="5dp"
/>
You can download Fonts from Google Material
view
and view All Attributes
on your right side and find fontFamily
down arrow
, it will open a window for selecting fontFind your desired font, you can also search and click ok
Your Chronometer
will look differently
Here is the code
<Chronometer
android:id="@+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:fontFamily="@font/allan_bold"
android:textColor="@color/colorAccent"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
If in case font does not change use this in your Activity.class
Chronometer chronometer = findViewById(R.id.chronometer);
chronometer.setTypeface(ResourcesCompat.getFont(this, R.font.allan_bold));
//replace allan_bold with your desired font
Edit 1
Here is the Output in the device
Hope this will help!