Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
832 views
in Technique[技术] by (71.8m points)

xml - I want to show the Reginonal language(Gurumukhi) in my Android app

I want the output as shown in below image

This is in Gurumukhi Font

This is a Sikh holy book which uses the Regional font(Gurumukhi) and i want to make an xml file of this text to use the xml parsing to show in my application. But the Problem is when i paste this font in my xml file it converts into the some alphabets and symbols like below

jpujI swihb
<> siq nwmu krqw purKu inrBau inrvYru
Akwl mUriq AjUnI sYBM gur pRswid ]
] jpu ]
Awid scu jugwid scu ]
hY BI scu nwnk hosI BI scu ]1]
socY soic n hoveI jy socI lK vwr ]
cupY cup n hoveI jy lwie rhw ilv qwr ]
BuiKAw BuK n auqrI jy bMnw purIAw Bwr ]
shs isAwxpw lK hoih q iek n clY nwil ]
ikv sicAwrw hoeIAY ikv kUVY qutY pwil ]
hukim rjweI clxw nwnk iliKAw nwil ]1]
hukmI hovin Awkwr hukmu n kihAw jweI ]
hukmI hovin

I have placed a Gurumukhi font file in the asset folder and use the below code which works fine

Typeface tf = Typeface.createFromAsset(getAssets(),
                "fonts/bulara_5.ttf");
        textView = (TextView) findViewById(R.id.textView1);
        textView.setTypeface(tf);
        textView.setMovementMethod(new ScrollingMovementMethod());
        textView.setText(" <>siq nwmu krqw purKu inrBau inrvYru")

In that way the text in that text view converts into the Gurumukhi but How can i create my Xml file for this type of text in it. Or Give me some Good Suggestion that which way is better to work on this type of app and handle the text. I have to show 4-5 Holy books in one app and each have 20-25 pages. Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Update Since you want to use via XML Your layout.xml should be like

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

    <com.nannu.NanTV
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/book"
        android:textAppearance="?android:attr/textAppearanceLarge" 

        />

</LinearLayout>

and string.xml

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


    <string name="book"><![CDATA[jpujI swihb\<> siq nwmu krqw purKu inrBau inrvYruAkwl mUriq AjUnI sYBM gur pRswid ]] jpu ]Awid scu jugwid scu ]hY BI scu nwnk hosI BI scu ]1]socY soic n hoveI jy socI lK vwr ]cupY cup n hoveI jy lwie rhw ilv qwr ]BuiKAw BuK n auqrI jy bMnw purIAw Bwr ]shs isAwxpw lK hoih q iek n clY nwil ]ikv sicAwrw hoeIAY ikv kUVY qutY pwil ]hukim rjweI clxw nwnk iliKAw nwil ]1]hukmI hovin Awkwr hukmu n kihAw jweI ]hukmI hovin]]></string>
</resources>

Hello Extend your textview

package com.nannu;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class NanTV extends TextView{

    private Context c;
    public NanTV(Context c) {
        super(c);
        this.c = c;
        Typeface tfs = Typeface.createFromAsset(c.getAssets(),
                "font/bulara_5.ttf");
        setTypeface(tfs);

    }
    public NanTV(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.c = context;
        Typeface tfs = Typeface.createFromAsset(c.getAssets(),
                "font/bulara_5.ttf");
        setTypeface(tfs);
        // TODO Auto-generated constructor stub
    }

    public NanTV(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.c = context;
        Typeface tfs = Typeface.createFromAsset(c.getAssets(),
                "font/bulara_5.ttf");
        setTypeface(tfs);

    }


}

Now Your layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

    <com.nannu.NanTV
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" 

        />

</LinearLayout>

Activity

package com.nannu;

import android.app.Activity;
import android.os.Bundle;

public class NanDempoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        NanTV nan = (NanTV)findViewById(R.id.textView1);
        nan.setText("jpujI swihb<> siq nwmu krqw purKu inrBau inrvYruAkwl mUriq AjUnI sYBM gur pRswid ]] jpu ]Awid scu jugwid scu ]hY BI scu nwnk hosI BI scu ]1]socY soic n hoveI jy socI lK vwr ]cupY cup n hoveI jy lwie rhw ilv qwr ]BuiKAw BuK n auqrI jy bMnw purIAw Bwr ]shs isAwxpw lK hoih q iek n clY nwil ]ikv sicAwrw hoeIAY ikv kUVY qutY pwil ]hukim rjweI clxw nwnk iliKAw nwil ]1]hukmI hovin Awkwr hukmu n kihAw jweI ]hukmI hovin");
    }
}

Final Output


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...