title: How to set Google Fonts .xml programmatically to TextView
body: <p>Since with Android Studio 3.0, you can simply integrate google fonts to your project <a href="https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html#via-android-studio" rel="noreferrer">(See android walkthrough)</a>.</p>
  
  <p>When you add some font, Android Studio generates you the font folder including XML file for the font (in my case amatic_sc.xml). Also Studio create a preloaded_fonts.xml in value folder. </p>
  
  <p>amatic_sc.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;font-family xmlns:app="http://schemas.android.com/apk/res-auto"
          app:fontProviderAuthority="com.google.android.gms.fonts"
          app:fontProviderPackage="com.google.android.gms"
          app:fontProviderQuery="Amatic SC"
          app:fontProviderCerts="@array/com_google_android_gms_fonts_certs"&gt;
  &lt;/font-family&gt;
  </code></pre>
  
  <p>preloaded_fonts.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;array name="preloaded_fonts" translatable="false"&gt;
          &lt;item&gt;@font/amatic_sc&lt;/item&gt;
      &lt;/array&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>When I'm include the following line static into my xml file, it works fine:</p>
  
  <pre><code>android:fontFamily="@font/amatic_sc"
  </code></pre>
  
  <p>But in my case I need to set the font family programmatically in my custom listAdapter. I tried following code exemples, but nothing works:</p>
  
  <pre><code>// Display text with default fontFamily
  viewHolder.textView.setTypeface(Typeface.create("@font/amatic_sc", Typeface.NORMAL));
  
  // both throws java.lang.RuntimeException: Font asset not found [../res/]font/amatic_sc.xml
  viewHolder.textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "font/amatic_sc.xml"));
  viewHolder.textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "../res/font/amatic_sc.xml"));
  
  // both throws java.lang.RuntimeException: Font asset not found [../res/]font/amatic_sc.xml
  viewHolder.textView.setTypeface(Typeface.createFromFile("font/amatic_sc.xml"));
  viewHolder.textView.setTypeface(Typeface.createFromFile("../res/font/amatic_sc.xml"));
  </code></pre>
  
  <p>In my case, I use min <strong>SDK version 16</strong> and I hope my code snippet is sufficient.</p>
  
  <p>Thanks for the help!</p>