Typeface does not change the font

Asked

Viewed 54 times

0

My font is not changing, the font file font1.ttf is in the Assets folder

Class

package br.com.paivasdev.fazendocafe;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class Passo8Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.passo8);

    TextView txt = (TextView) findViewById(R.id.texto_fonte);
    Typeface font = Typeface.createFromAsset(getAssets(), "font1.ttf");
    txt.setTypeface(font);

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TesteFonte"
    android:id="@+id/texto_fonte"
    android:textSize="50sp"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="53dp"
    android:layout_marginStart="53dp"
    android:layout_marginTop="217dp" />



    </RelativeLayout>
  • Is the file in a folder? e. g: Assets/fonts/...

  • No, it’s on the Assets, and the Assets I created in the app folder is right ?

  • http://prntscr.com/eo1py0 looks like this? Ignore the "Kotlin" folder, yours will look like "Java"... Anyway, it looks like this?

  • Error appears in logcat?

1 answer

0

You must have created the Assets folder in the wrong location.

Change your project’s preview from android to project:

inserir a descrição da imagem aqui

Then insert the Assets folder into the folder main (seuapp/app/src/main/Assets):

inserir a descrição da imagem aqui

  • Mine is just like your friend

  • its font can handle the size of up to 50sp?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.