Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>public static ViewGroup setFont(Context context, ViewGroup group, Typeface font) { int count = group.getChildCount(); View v = null; for(int i = 0; i &lt; count; i++) { v = group.getChildAt(i); if(v instanceof TextView || v instanceof Button || v instanceof EditText/*etc.*/) ((TextView)group.getChildAt(i)).setTypeface(font); else if(v instanceof ViewGroup) setFont(context, (ViewGroup)v, font); } return group; } </code></pre> <p>Then in your in your main edit the call to something like this:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //--Get font style to be applied from assets folder-- Typeface font =Typeface.createFromAsset(getAssets(), "Sansation_Bold_Italic.ttf"); ViewGroup root = (ViewGroup)findViewById(R.id.myrootlayout); root = (ViewGroup) AndroidTFFActivity.setFont(this,root, font); } </code></pre> <p>Also, make sure you have the right permissions set in your manifest to read the file. I took your sample and ran it successfully on my end, let me know if this helps.</p> <p>This is an example of the xml I used to test with:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:id="@+id/myrootlayout"&gt; &lt;TextView android:id="@+id/txtTest1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="test 1" /&gt; &lt;TextView android:id="@+id/txtTest2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="test 2" /&gt; &lt;TextView android:id="@+id/txtTest3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="test 3" /&gt; &lt;/LinearLayout&gt; </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. 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