2017-08-02 6 views
0

ich lese diese Seite https://developer.android.com/preview/features/fonts-in-xml.html Textansicht ist in Ordnung, aber Textclock ist nicht funktionieren.android textclock set fontfamily nicht arbeiten

<?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

Wie kann ich die TextClock Arbeit wie Textview zu machen?

Ich schreibe den TextClock in einem Widget, remoteview kann die TextClock-Instanz nicht abrufen. Ich werde die Schriftart TextClock ändern, aber ich weiß nicht, wie ich sie ändern soll.

Hoffe jemand kann mir helfen, dieses Problem zu lösen.

Antwort

0

Ich habe meine Schriften im Ordner Assets/Fonts gespeichert. Ich mache dann folgendes.

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