Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this is duplicate of <a href="https://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime">this question</a> and <a href="https://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android">this one</a>.</p> <p>In my activities in runtime, I use something like this:</p> <pre><code>FontUtils.setCustomFont(findViewById(R.id.top_view), getAssets()); </code></pre> <p>In XML:</p> <pre><code> &lt;TextView android:id="@+id/my_label" android:tag="condensed" android:text="@string/label" ... /&gt; </code></pre> <p>So theoretically you can create style and use it together with FontUtils/runtime code. </p> <pre><code>&lt;style name="roboto_condensed"&gt; &lt;item name="android:tag"&gt;condensed,your-own-css-like-language-here&lt;/item&gt; &lt;/style&gt; </code></pre> <p>FontUtils class:</p> <pre><code>public class FontUtils { private static Typeface normal; private static Typeface bold; private static Typeface condensed; private static Typeface light; private static void processsViewGroup(ViewGroup v, final int len) { for (int i = 0; i &lt; len; i++) { final View c = v.getChildAt(i); if (c instanceof TextView) { setCustomFont((TextView) c); } else if (c instanceof ViewGroup) { setCustomFont((ViewGroup) c); } } } private static void setCustomFont(TextView c) { Object tag = c.getTag(); if (tag instanceof String) { if (((String) tag).contains("bold")) { c.setTypeface(bold); return; } if (((String) tag).contains("condensed")) { c.setTypeface(condensed); return; } if (((String) tag).contains("light")) { c.setTypeface(light); return; } } c.setTypeface(normal); } public static void setCustomFont(View topView, AssetManager assetsManager) { if (normal == null || bold == null || condensed == null || light == null) { normal = Typeface.createFromAsset(assetsManager, "fonts/roboto/Roboto-Regular.ttf"); bold = Typeface.createFromAsset(assetsManager, "fonts/roboto/Roboto-Bold.ttf"); condensed = Typeface.createFromAsset(assetsManager, "fonts/roboto/Roboto-Condensed.ttf"); light = Typeface.createFromAsset(assetsManager, "fonts/roboto/Roboto-Light.ttf"); } if (topView instanceof ViewGroup) { setCustomFont((ViewGroup) topView); } else if (topView instanceof TextView) { setCustomFont((TextView) topView); } } private static void setCustomFont(ViewGroup v) { final int len = v.getChildCount(); processsViewGroup(v, len); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload