Asif Lijaz
Asif Lijaz

Reputation: 35

How can i use malayalam ASCII fonts?

I am a beginner in app developers.I am facing a problem while adding ASCII fonts in Text View.How can i add some text in the text box which are in ASCII.

Upvotes: 2

Views: 349

Answers (2)

steveen zoleko
steveen zoleko

Reputation: 395

Switch your text encoding to UTF-8.

In Eclipse go to Window -> Preferences, select General -> Workspace. From the Text file encoding dropdown, select UTF-8.

do as follows:

download AnjaliOldLipi.ttf font.that's the malayalam font .search google for the file. under your android assets folder create if not exist the folder fonts: assets/fonts/AnjaliOldLipi.ttf

then display texts this way were textview is a TextView: textview.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/AnjaliOldLipi.ttf"))

Upvotes: 1

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

There are two approach that you can use

1) If data is contains HTML along with ASCII.

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

2) If data is contains only ASCII.

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

Example:

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>

Outout:

enter image description here

NOTE:

Put APPLET.TTF file in assets folder of your project

Upvotes: 1

Related Questions