简体   繁体   English

如何更改android中的字体语言

[英]How to change the font language in android

In my app i want to convert my english font into hindi, for that i did localization. 在我的应用程序中,我想将我的英文字体转换为印地文,因为我做了本地化。 that is not supported for lower versions(ie 2.3). 较低版本(即2.3)不支持。 Then i downloaded " shusha.ttf " file and added to assets/fonts folder. 然后我下载了“ shusha.ttf ”文件并添加到assets / fonts文件夹中。 Then i set the typeface for a textviews. 然后我为textviews设置字体。 Like this i am able to convert the english font to hindi. 像这样我能够将英文字体转换为印地文。 but when i get the text from the text view it is not showing in Hindi(getting the english font). 但是当我从文本视图中获取文本时,它不会显示为印地语(获取英文字体)。 i am using that text to send the mail through gmail. 我正在使用该文本通过Gmail发送邮件。

If any body have idea about this please give me a suggestion. 如果有任何人对此有所了解,请给我一个建议。

This is my Code 这是我的代码

 t = ((TextView)findViewById(R.id.textView1));
     t2 = ((TextView)findViewById(R.id.textView2));
     Typeface Hindi = Typeface.createFromAsset(getAssets(), "fonts/shusha.ttf");
     t.setTypeface(Hindi);
     t.setTextSize(20);
     String hello=" Hyderabad, Andhra Pradesh, India ";
     t.setText(hello);
     String lang=t.getText().toString().trim();
     t2.setText(lang);

Instead of using and playing with font, use UNICODE characters for hindi words. 不使用和播放字体,而是使用UNICODE字符作为印地语单词。 I had done it for a project of mine and it works great. 我是为我的一个项目做的,它运作得很好。

You have to change the font of the text of text view. 您必须更改文本视图的文本字体。

First put the font in your asset folder. 首先将字体放在资产文件夹中。

Then in your java file add code like this to change your font: 然后在你的java文件中添加这样的代码来改变你的字体:

Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),
                    "shusha.ttf");
TextView digital= (TextView) findViewById(R.id.your_textView);
            digital.setTypeface(myTypeface);

Put shusha.ttf in your asset folder of your project. 将shusha.ttf放入项目的资产文件夹中。

This will might help you. 这可能会对你有所帮助。

Create styles in values/styles like, 在值/样式中创建样式,如,

<style name="MyStyle" parent="@android:style/Theme">
        <item name="typeface">font_in_assest.ttf</item>
</style>

Here, font_in_assest.ttf is the font you placed in your assests/fonts. 这里,font_in_assest.ttf是您在assests / fonts中放置的字体。 Then assign the style for you view, 然后为您查看样式,

<TextView
        android:id="@+id/title"
        style="@style/MyStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />   

It will be helpful for you.. 这对你有帮助..

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

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