Java 在Android中使用印地语字体

Java 在Android中使用印地语字体,java,android,xml,hindi,Java,Android,Xml,Hindi,我无法理解,尽管在string.xml代码中提到了utf-8编码,“ddd”为什么没有被编码为所需的字体(DevLys 180,一种印地语字体) 我从互联网上复制了这段代码,以便在我的应用程序中使用印地语: Main.Activity java: package com.example.spk.muni_darshan; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundl

我无法理解,尽管在string.xml代码中提到了utf-8编码,“ddd”为什么没有被编码为所需的字体(DevLys 180,一种印地语字体)

我从互联网上复制了这段代码,以便在我的应用程序中使用印地语:

Main.Activity java:

package com.example.spk.muni_darshan;

import android.app.Activity;
import android.graphics.Typeface;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView tv = (TextView) findViewById(R.id.titleText);
Typeface font = Typeface.createFromAsset(getAssets(),
        "font/DevLys 180.ttf");
tv.setTypeface(font);

}
string.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>
           <string name="app_name">Muni_Darshan</string>
           <string name="font">font</string>
           <string name="title">ddddd</string>
</resources>
<TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/title"
          android:id="@+id/titleText"
          android:textSize="@dimen/abc_action_bar_default_height_material"
          android:fontFamily="@string/font" />

穆尼乌达山
字体
DDD
活动\u main.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>
           <string name="app_name">Muni_Darshan</string>
           <string name="font">font</string>
           <string name="title">ddddd</string>
</resources>
<TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/title"
          android:id="@+id/titleText"
          android:textSize="@dimen/abc_action_bar_default_height_material"
          android:fontFamily="@string/font" />

通过setTypeface在代码中设置字体时,可能不必在xml中设置fontFamily选项。 具体而言:

android:fontFamily="@string/font"
您可以尝试删除此项

另外,请确保您正在将字体打包到assets/font文件夹中。您可以解压缩APK以验证这一点

AKAIK:没有直接的方法来指定XML中的自定义打包字体。它必须通过代码来完成


我通常做的是创建TextView的派生类,并在xml中使用它。在这个新类的构造函数中,您已经根据代码设置了字体

我已将ttf文件复制粘贴到font文件夹中。其位置:app/src/main/assets/font。我已删除fontfamily代码。您是否看到上述代码未能交付印地语字体的任何其他原因?1)保留资产/font并不保证它将打包到APK中。您的构建配置可能不知道这一点。只要试着解压构建的APK文件,看看你的字体是否在那里?(压缩)2)验证字体文件是否正常。尝试在windows计算机上打开该文件?可能已将.iml文件转换为.rar,但之后无法将其解压缩。没有.apk文件。请您进一步指导。thanksapk文件是您推送到设备/仿真器的最终软件包。