繁体   English   中英

如何在我的Android应用中使用Roboto

[英]How do I use Roboto in my android app

我一直在研究如何在Android应用中使用Roboto。 我偶然发现了一个看起来很有前途的git项目,该项目专门用于我需要的东西。 但是当我下载该项目时,它拒绝工作。 我作为故障排除尝试的一些事情

  • 属性> android> android 4.4.2
  • minSdkVersion 3更改为11: android:minSdkVersion="11"

我还在

error: No resource identifier found for attribute 'typeface' in package 
 'com.devspark.robototextview.sample'

在单个布局文件中: activity_main.xml

该项目位于https://github.com/johnkil/Android-RobotoTextView

有谁知道我可能会如何使它工作,或者在使用如此简单的Roboto方面有一些建议?

更新

我在Mac OS X特立独行者上使用Eclipse。 我刚刚检查了一下,发现src文件夹为空,而MainActivity.java文件实际上位于以下文件夹的路径下: java>com>devspark>robototextview>sample 因此,我的第一个猜测是eclipse不知道如何导入项目。 没有人知道我怎么解决这个问题,如果确实是问题所在。 顺便说一下,我所有的项目都在git上,并且我已经使用git的示例和库已有一段时间了。 因此问题可能出在这个特定项目上。

样本布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <TextView
            android:id="@+id/custom_font"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="This is the roboto font."/>

</LinearLayout>

将字体文件放置在资产/字体中(在资产文件夹中创建字体)

活动内部:

TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
txt.setTypeface(font);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM