2017-08-02 107 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);