set custom font for text in PreferenceScreen

后端 未结 4 825
独厮守ぢ
独厮守ぢ 2020-12-15 00:08

My PreferenceActivity looks like:

import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 00:49

    With the addition of font support in android O, we can now set a font-family to app theme and that would automatically reflect in the PreferenceFragment as well. (Note: I am using PreferenceFragmentCompat). First add a font-family to the resources like this:

    
    
    
    
    

    NOTE: You would need both app and android namespace declarations as of now Link

    Then add a style for the text view mentioning this font-family for the TextView:

    
    

    And then finally, just refer to the above style in your AppTheme like this:

    
    

    Done. This will show the customised font in your PreferenceFragmentCompat as well.

提交回复
热议问题