Custom font for my Android app not showing up on physical device

62 Views Asked by At

I've tried a bunch of things, like setting the font on a layout level, creating a typeface and setting it, and cleaning and rebuilding the project. The font will show up in the editor, and last I was able to try it, the emulator (though my computer hasn't been the greatest lately), but not my Samsung Galaxy Note 3. Here's the Java code:

`

package com.example.benkyoblobandroid;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.Group;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

public class BlobView extends AppCompatActivity {

    ImageButton pet;
    Group infoGroup;
    ImageButton studyTimeButton;
    TextView HPLabel;
    TextView EXPLabel;
    TextView EXP;
    TextView lvl;
    Typeface pixelFont;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        HPLabel = (TextView) findViewById(R.id.HP);
        EXPLabel = (TextView) findViewById(R.id.EXPLabel);
        EXP = (TextView) findViewById(R.id.EXP);
        lvl = (TextView) findViewById(R.id.lvl);
        pixelFont = Typeface.createFromAsset(getAssets(),
                "font/fff_forward_regular");
        HPLabel.setTypeface(pixelFont);
        EXPLabel.setTypeface(pixelFont);
        EXP.setTypeface(pixelFont);
        lvl.setTypeface(pixelFont);
        pet = (ImageButton) findViewById(R.id.pet);
        infoGroup = (Group) findViewById(R.id.infoGroup);
        pet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                infoGroup.setVisibility(infoGroup.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
            }
        });
        studyTimeButton = (ImageButton) findViewById(R.id.studyTimeButton);
        studyTimeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchActivity(StudyTimeView.class);
            }
        });
    }

    void switchActivity(Class activity) {
        Intent activityIntent = new Intent(this, activity);
        startActivity(activityIntent);
    }
}`

And the XML code:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BlobView">

    <ImageView
        android:id="@+id/background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="1:2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/blob_room" />

    <ImageButton
        android:id="@+id/pet"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@null"
        android:contentDescription="Pet"
        android:scaleType="fitCenter"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/guideline2"
        app:srcCompat="@drawable/slimepet_pink" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.40" />

    <ImageView
        android:id="@+id/info"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="147dp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintDimensionRatio="2:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/background"
        app:srcCompat="@drawable/flashcard" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.20" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.50" />


    <androidx.constraintlayout.widget.Group
        android:id="@+id/infoGroup"
        android:layout_width="54dp"
        android:layout_height="7dp"
        android:visibility="visible"
        app:constraint_referenced_ids="info,infoText,EXPStar,lvl"
        tools:layout_editor_absoluteX="185dp"
        tools:layout_editor_absoluteY="246dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/leftInfoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.05" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/topInfoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.23" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/bottomInfoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.43" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/rightInfoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.90" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/midInfoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.31" />

    <LinearLayout
        android:id="@+id/infoText"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:paddingTop="10sp"
        app:layout_constraintBottom_toBottomOf="@id/bottomInfoGuideline"
        app:layout_constraintEnd_toEndOf="@id/rightInfoGuideline"
        app:layout_constraintStart_toStartOf="@id/leftInfoGuideline"
        app:layout_constraintTop_toTopOf="@id/topInfoGuideline">

        <LinearLayout
            android:id="@+id/happiness"
            android:layout_width="350sp"
            android:layout_height="50sp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="@id/HP"
            app:layout_constraintDimensionRatio="2:1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <TextView
                android:id="@+id/HP"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hp"
                android:textSize="30sp"
                android:fontFamily="@font/font"
            />

            <ImageView
                android:id="@+id/health1"
                android:layout_width="50sp"
                android:layout_height="50sp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/health_empty" />

            <ImageView
                android:id="@+id/health2"
                android:layout_width="50sp"
                android:layout_height="50sp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/health_empty" />

            <ImageView
                android:id="@+id/health3"
                android:layout_width="50sp"
                android:layout_height="50sp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/health_empty" />

            <ImageView
                android:id="@+id/health4"
                android:layout_width="50sp"
                android:layout_height="50sp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/health_empty" />

            <ImageView
                android:id="@+id/health5"
                android:layout_width="50sp"
                android:layout_height="50sp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/health_empty" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/expInfo"
            android:layout_width="350sp"
            android:layout_height="100sp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="@id/bottomInfoGuideline"
            app:layout_constraintDimensionRatio="2:1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@id/leftInfoGuideline"
            app:layout_constraintTop_toBottomOf="@id/happiness"
            app:layout_constraintTop_toTopOf="@id/midInfoGuideline">

            <TextView
                android:id="@+id/EXPLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/font"
                android:text="@string/exp"
                android:textSize="30sp"
            />

            <TextView
                android:id="@+id/EXP"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/font"
                android:text="@string/EXP"
                android:textSize="30sp"
            />

        </LinearLayout>
    </LinearLayout>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/starStartGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.55" />

    <ImageView
        android:id="@+id/EXPStar"
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintStart_toStartOf="@id/starStartGuideline"
        app:layout_constraintTop_toTopOf="@id/midInfoGuideline"
        app:srcCompat="@drawable/exp_star" />

    <TextView
        android:id="@+id/lvl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/font"
        android:text="1"
        android:textColor="#FF0000"
        android:textSize="25sp"
        app:layout_constraintEnd_toEndOf="@id/EXPStar"
        app:layout_constraintStart_toStartOf="@id/EXPStar"
        app:layout_constraintTop_toTopOf="@id/EXPStar"
        />

    <LinearLayout
        android:layout_width="350sp"
        android:layout_height="70sp"
        app:layout_constraintTop_toTopOf="@id/iconsTop"
        app:layout_constraintStart_toStartOf="@id/leftInfoGuideline"
        app:layout_constraintEnd_toEndOf="@id/rightInfoGuideline">
        <ImageButton
            android:id="@+id/studyTimeButton"
            android:layout_width="50sp"
            android:layout_height="50sp"
            android:background="@null"
            android:scaleType="fitCenter"
            app:layout_constraintDimensionRatio="1:1"
            app:srcCompat="@drawable/ui_01_study_time_light_with_colored_shadow"
            tools:layout_editor_absoluteX="67dp"
            tools:layout_editor_absoluteY="102dp"
            android:contentDescription="Study Time"
            />
    </LinearLayout>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/iconsTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="20dp" />



</androidx.constraintlayout.widget.ConstraintLayout>

Attached are how it looks in the editor vs. how it looks on my Android, and also the file hierarchy. Font works in editor.Font does not work on device.Fonts in the file hierarchy.

0

There are 0 best solutions below