如何在android活动中添加新字体

如何在android活动中添加新字体,android,textview,android-fonts,Android,Textview,Android Fonts,我开发了一个android应用程序,现在我正在尝试向它添加(Kulturista Bold.ttf)这个自定义字体,但它不起作用,这里是我的login.xml文件和login.java文件 <TextView android:id="@+id/maintitle" android:layout_width="fill_parent" android:layout_height="wrap_con

我开发了一个android应用程序,现在我正在尝试向它添加(Kulturista Bold.ttf)这个自定义字体,但它不起作用,这里是我的login.xml文件和login.java文件

<TextView
                android:id="@+id/maintitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="CREATE AN ACCOUNT?"
                android:textColor="@color/blue"
                android:textSize="25dp"
                android:layout_gravity="center"
                   android:layout_marginTop="70dp"
                android:gravity="center"/>
        <TextView
            android:id="@+id/subtitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="CLICK ON THE SIGHNUP AND REGISTER"
            android:textColor="#c4cbcf"
            android:layout_gravity="center"
            android:gravity="center"
             />
删除“.ttf”中的空格

通过删除空间来尝试此操作

Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf"); 

尝试在
getAssets
之前添加
getContext
activityName

Typeface font = Typeface.createFromAsset(getContext(),"fonts/androidnation.ttf");

试试这个

Typeface typeFace = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");
txt2.setTypeface(typeFace);

如果您只能从“资源”文件夹访问,则只需在代码中从中删除空间即可。ttf

所以改变它

Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");
如果您已在“资源”文件夹中创建了名为“字体”的文件夹,则必须通过访问该文件夹

Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Kulturista_Bold.ttf");

你的字体是否与此相同?你的资产文件夹是否与此相同。ttf一旦检查名称,可能会使用此
Kulturista\u Bold.ttf
您的
ttf
文件在哪里?在资产文件夹中?
Typeface typeFace = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");
txt2.setTypeface(typeFace);
Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");
Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Kulturista_Bold.ttf");