title: Android custom fonts Lollipop
body: <p>I have two TextView which I want to put a custom font on.</p>
  
  <p>In the OnCreate of my MainActivity, after the setContentView call, I wrote the following code:</p>
  
  <pre><code>Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
  TextView welcomeTextView = (TextView)findViewById(R.id.welcome_message);
  TextView introTextView = (TextView)findViewById(R.id.introduction_message);
  
  welcomeTextView.setTypeface(myTypeface);        
  introTextView.setTypeface(myTypeface);
  </code></pre>
  
  <p>But for some reason, the font stays default.</p>
  
  <p>The app runs on Galaxy S6 Edge device (Lollipop 5.0.2).</p>
  
  <p>I read <a href="https://code.google.com/p/android-developer-preview/issues/detail?id=608" rel="nofollow">here</a> that there's a problem with custom fonts on Lollipop, and in order to fix it I converted my font with the tool provided in the thread to ttx and vice versa, but even this didn't help.</p>
  
  <p>Any ideas what can I do?</p>
  
  <p>Edit:
  Tested on Jellybean (4.3), not working either.</p>
  
  <p><strong>Another edit:
  It works on a clean new project! Cant figure out the difference.
  Putting the MainActivity and its' XML for help:</strong></p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
  private LoginFragment loginFragment;
  private TextView welcomeTextView;
  private TextView introTextView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      hideActionBar();
      setContentView(R.layout.activity_main);
  
      welcomeTextView = (TextView)findViewById(R.id.welcome_message);
      introTextView = (TextView)findViewById(R.id.introduction_message);
  
      Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
      welcomeTextView.setTypeface(myTypeface);
      introTextView.setTypeface(myTypeface);
  
      if (savedInstanceState == null) {
          // Add the fragment on initial activity setup
          loginFragment = new LoginFragment();
          getSupportFragmentManager().beginTransaction()
                  .add(android.R.id.content, loginFragment, "facebookFragment").commit();
  
      }
  
  }
  
  
  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
  
      if(hasFocus){
          // get all views on screen
          ArrayList&lt;View&gt; views = new ArrayList&lt;View&gt;()
          {{
              add(findViewById(R.id.welcome_message));
              add(findViewById(R.id.introduction_message));
              add(findViewById(R.id.below_login));
              add(findViewById(R.id.above_login));
              add(findViewById(R.id.authButton));
              add(findViewById(R.id.logo));
          }};
  
          // set animations
          for(View view : views)
              YoYo.with(Techniques.Tada).duration(700).playOn(view);
  
      }
  }
  
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public void hideActionBar(){
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB)
          getActionBar().hide();
  }
  </code></pre>
  
  <p>And the activity's XML:</p>
  
  <pre><code>&lt;RelativeLayout 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:background="@drawable/main_background"&gt;
  
  &lt;ImageView
      android:id="@+id/logo"
      android:layout_width="256dp"
      android:layout_height="101dp"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="40dp"
      android:background="@drawable/logo" /&gt;
  
  &lt;RelativeLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:layout_marginStart="20dp"
      android:layout_marginLeft="20dp"
      android:layout_marginEnd="20dp"
      android:layout_marginRight="20dp"&gt;
  
      &lt;TextView
          android:id="@+id/welcome_message"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:text="@string/welcome_message"
          android:textColor="@color/White"
          android:textSize="25sp"
          style="@style/ShadowStyleText"
          android:gravity="center" /&gt;
  
  
      &lt;TextView
          android:id="@+id/introduction_message"
          android:layout_below="@+id/welcome_message"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:text="@string/introduction_message"
          android:textColor="@color/White"
          android:textSize="18sp"
          android:gravity="center"
          style="@style/ShadowStyleText"
          android:layout_marginTop="5dp" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      android:id="@+id/bottom_login_chunk"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="50dp" 
      android:layout_marginStart="50dp"
      android:layout_marginLeft="50dp"
      android:layout_marginEnd="50dp"
      android:layout_marginRight="50dp"&gt;
  
      &lt;TextView
          android:id="@+id/above_login"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:text="@string/above_login_button"
          android:textColor="@color/White"
          android:textSize="18sp"
          style="@style/ShadowStyleText"
          android:gravity="center" /&gt;
  
      &lt;com.facebook.widget.LoginButton
          android:id="@+id/authButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/above_login"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="5dp"
          android:layout_marginTop="5dp" /&gt;
  
      &lt;TextView
          android:id="@+id/below_login"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/authButton"
          android:layout_centerHorizontal="true"
          android:text="@string/below_login_button"
          android:textColor="@color/White"
          style="@style/ShadowStyleText"
          android:textSize="14sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>