2

i read this page https://developer.android.com/preview/features/fonts-in-xml.html textview is ok ,but textclock is not work.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hellokai.myapplication.MainActivity">

    <TextClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/oswald_stencbab"
        android:format12Hour="hh:mm"
        android:format24Hour="hh:mm"
        android:textSize="60dp"
        android:text="hello"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:textSize="60dp"
        android:text="@string/app_name"
        android:fontFamily="@font/oswald_stencbab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</android.support.constraint.ConstraintLayout>

enter image description here

How can I make the TextClock work like TextView?

I write the TextClock in a widget,remoteview can't get the TextClock instance. I will change the TextClock font,but i don't konw how to change it.

Hope someone can help me solve this problem.

kai hello
  • 135
  • 1
  • 2
  • 13

2 Answers2

1

I saved my fonts in assets/fonts folder. I then do the following.

Typeface typeFaceBlack = Typeface.createFromAsset(context.getAssets(), "fonts/Font.otf");
textClockID.setTypeface(typeFaceBlack);
letsCode
  • 2,774
  • 1
  • 13
  • 37
0

You need to create your own custom clock, instead of using built-in textclock.

in order to do it:

import java.util.Calendar;

then get hour & minute:

Calendar cal = Calendar.getInstance(); 
int minutes = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR_OF_DAY);

and in the end set both hour and minute on 2 seperate TextView and then apply the typeface