android - 如何使用马拉雅拉姆语 ASCII 字体?

标签 android

我是应用程序开发人员的初学者。我在 TextView 中添加 ASCII 字体时遇到问题。如何在文本框中添加一些 ASCII 文本。

最佳答案

您可以使用两种方法

1) 如果数据包含 HTML 和 ASCII。

 txtview.setText(Html.fromHtml(asciiString));

2) 如果数据仅包含 ASCII。

try {
        textView.setText(new String(asciiString.getBytes("UTF-8"),"UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

示例:

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        TextView textView = (TextView) findViewById(R.id.textView);

        try {
            textView.setTypeface(Typeface.createFromAsset(getAssets(), "APPLET.TTF"));
            textView.setText(new String("bYmÀ° AÀlXbpÅh³".getBytes("UTF-8"),"UTF-8"));

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >

   <TextView
       android:id="@+id/textView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       />

</RelativeLayout>

输出:

enter image description here

注意:

APPLET.TTF文件放入项目的assets文件夹中

关于android - 如何使用马拉雅拉姆语 ASCII 字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25078058/

相关文章:

android - 如何挂接到所有 Android 点击事件?

iphone - iphone 和 android 的 sip 堆栈

android - 如何从 AChartEngine GraphicalView 绘制位图

Android - Forecast.io 图标标签自定义字体 : weather-icons

android - asmack如何知道消息发送失败

Android 谷歌地图 api v2 - 缺少 Google Play 服务

android - 我如何在 flutter 中单击交错 GridView 中的项目

android - 如果我最小化我的应用程序或关闭屏幕(谷歌地图),折线将无法正常工作

java - 包名称更改导致永久权限问题

android - DataApi 是否可靠且几乎是实时的?极度延迟