如何使用Android的工作室自定义字体自定义、如何使用、字体、工作室

2023-09-06 14:34:37 作者:我要的爱你给不起

我试图用自定义的字体在Android的工作室,因为我们在Eclipse一样。但遗憾的是无法弄清楚哪里放了资产文件夹!

I was trying to use custom font in Android Studio as we did in Eclipse. But unfortunately could not figure out where to put the 'assets' folder!

推荐答案

下面是几个步骤来解决它:

Here is the few steps to solve it:

转到(项目文件夹) 和应用程序>来源>主 创建文件夹的资产>字体到主要文件夹。

把你的'abc.ttf到字体文件夹。 Go to the (project folder) Then app>src>main Create folder 'assets>fonts' into the main folder.

Put your 'abc.ttf' into the fonts folder.

    AssetManager am = context.getApplicationContext().getAssets();

    typeface = Typeface.createFromAsset(am,
            String.format(Locale.US, "fonts/%s", "abc.ttf"));

    setTypeface(typeface);

或尝试这种方式:

or try this way:

   TextView tx = (TextView)findViewById(R.id.textview1);

   Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/abc.ttf");

   tx.setTypeface(custom_font);