我试图在Android Studio中使用自定义字体,就像我们在Eclipse中所做的那样。但不幸的是,不知道在哪里放“资产”文件夹!


当前回答

现在有很多应用字体的方法,最简单的方法之一是这样的, 1)右键单击res文件夹 进入“新建> Android资源目录”。

2)从资源类型列表中选择字体,然后单击确定。

3)把你的字体文件放在字体文件夹里。

其他回答

把字体放在资产文件夹 然后应用fontfamily: " your fonts

如果你像我一样对Android非常陌生,这可能有点棘手。请务必致电:

TextView myTextView = (TextView) findViewById(R.id.textView);
Typeface typeface=Typeface.createFromAsset(getAssets(), "fonts/your font.ttf");
myTextView.setTypeface(typeface);

方法,例如onCreate。

现在有很多应用字体的方法,最简单的方法之一是这样的, 1)右键单击res文件夹 进入“新建> Android资源目录”。

2)从资源类型列表中选择字体,然后单击确定。

3)把你的字体文件放在字体文件夹里。

要在运行Android 4.1 (API级别16)及更高版本的设备上使用XML字体功能,请使用支持库26。有关使用支持库的更多信息,请参阅使用支持库一节。

添加字体作为资源,在Android Studio中执行以下步骤:

右键单击res文件夹,进入New > Android资源目录。 出现“新建资源目录”窗口。 在“资源类型”列表中选择字体,然后单击“确定”。 在字体文件夹中添加您的字体文件。

创建字体族 要创建字体族,请在Android Studio中执行以下步骤:

右键单击字体文件夹,选择新建>字体资源文件。出现“新建资源文件”窗口。 输入文件名,然后单击OK。新的字体资源XML在编辑器中打开。 在元素中包含每个字体文件、样式和权重属性。下面的XML演示了如何在字体资源XML中添加与字体相关的属性: 如果你的minSdkVersion是API级别26或更高

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font
        android:fontStyle="normal"
        android:fontWeight="400"
        android:font="@font/lobster_regular" />
    <font
        android:fontStyle="italic"
        android:fontWeight="400"
        android:font="@font/lobster_italic" />
</font-family>

如果你的minSdkVersion低于API级别26

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
    <font
        app:font="@font/lobster_italic"
        app:fontStyle="normal"
        app:fontWeight="400" />
</font-family>

然后你可以像这样在任何地方使用它

android:fontFamily="@font/your_custom_font_file"

我想补充一下我对Android- o和Android Studio 2.4的回答

在res文件夹下创建名为font的文件夹。下载要添加到项目示例谷歌fonts中的各种字体 在xml用户字体家族中 例子: < TextView android: fontFamily = " @font / indie_flower” android: layout_width = " wrap_content " android: layout_height = " wrap_content " android:填充= " 10 dp” android:文本= " @string / sample_text " / >

3.如果您希望它以编程的方式使用下面的代码

Typeface typeface = getResources().getFont(R.font.indie_flower);
textView.setTypeface(typeface);

要了解更多信息,请链接到我的博客文章字体样式的Android与Android Studio 2.4