0

I downloaded some fonts for Android Studio and I had to rename the files to be only lowercase because it didn't let me save them otherwise.

For instance, I have the file "bauhausregular.ttf"

However, when I reference the fonts on the activity_main.xml file, I have to put:

<TextView
            android:id="@+id/textView"
            android:layout_marginTop="10dp"
            android:textSize="12dp"
            android:font="@font/BauhausRegular"
            android:textFontWeight="300"/>

because if I put: "bauhausregular", it doesn't find it.

Then, when I build the project, I get this error:

Android resource linking failed com.example.myapp.app-mergeDebugResources-35:/layout/activity_main.xml:99: error: resource font/BauhausRegular (aka com.example.myapp:font/BauhausRegular) not found. error: failed linking file resources.

I can see in the Design view, that the fonts change even if it doesn't work when I build the project.

How can I solve this?

1 Answers1

0

Cerate a Custome TextView and use as per your requirements

public class RobotoTextView extends TextView {

public RobotoTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

public RobotoTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public RobotoTextView(Context context) {
    super(context);
    init();
}

private void init() {
    if (!isInEditMode()) {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Light.ttf");
        setTypeface(tf);
    }
}

}

usage

<com.test.RobotoTextView
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
Divyanshu
  • 462
  • 6
  • 17