VNTFontListPreference
This is an easy to use custom preference, which opens a dialog with a list of available fonts. The selected font gets automatically saved and you are able to set the font directory as well as the defaultValue.
<com.vanniktech.vntfontlistpreference.VNTFontListPreference
android:defaultValue="@string/font_face_default_value"
android:key="preference_font_face"
android:title="@string/font_face"
app:vnt_fontDirectory="@string/font_face_font_directory" />
vntfontlistpreference:vnt_fontDirectory
can be something like fonts
. This means that the dialog will list all fonts, that have the ending ttf
or otf
under assets/fonts
. If there are no fonts under the provided directory it will throw an exception during initialization.
Download Sample App
or scan the code on your mobile
or download it directly
Setup
build.gradle
compile 'com.vanniktech:vntfontlistpreference:1.0.0' compile 'com.vanniktech:vntfontlistpreference:1.0.1-SNAPSHOT'
Modules are located on Maven Central.
Go to your preference XML file and insert the above mentioned XML tag. Afterwards you are good to go and can run your project!
Get default font
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
final String defaultFont = sharedPreferences.getString("preference_font_face", this.getString(R.string.font_face_default_value));
final Typeface typeface = Typeface.createFromAsset(this.getAssets(), font);
Proguard
No configuration needed.
Preview
License
Copyright (C) 2014-2016 Vanniktech - Niklas Baudy
Licensed under the Apache License, Version 2.0