2017-08-02 87 views
0

我看到这个页面https://developer.android.com/preview/features/fonts-in-xml.html textview是好的,但是textclock不起作用。android textclock set fontfamily 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

我怎样才能让TextClock工作像TextView的?

我将TextClock写入小部件,remoteview无法获取TextClock实例。我将改变TextClock字体,但我不知道如何改变它。

希望有人能帮助我解决这个问题。

回答

0

我在资产/字体文件夹中保存了我的字体。然后我做了以下。

Typeface typeFaceBlack = Typeface.createFromAsset(context.getAssets(), "fonts/Font.otf"); 
textClockID.setTypeface(typeFaceBlack);