我是应用程序开发人员的初学者。我在 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>
输出:
注意:
将APPLET.TTF文件放入项目的assets文件夹中
关于android - 如何使用马拉雅拉姆语 ASCII 字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25078058/