我想在我的Android应用程序中显示Reginonal语言(Gurumukhi)

我想在我的Android应用程序中显示Reginonal语言(Gurumukhi),android,xml,localization,fonts,Android,Xml,Localization,Fonts,我希望输出如下图所示 这是一本使用区域字体(Gurumukhi)的锡克教圣书,我想制作一个文本的xml文件,使用xml解析在我的应用程序中显示。但问题是,当我将这种字体粘贴到xml文件中时,它会转换成一些字母和符号,如下所示 jpujI swihb <> siq nwmu krqw purKu inrBau inrvYru Akwl mUriq AjUnI sYBM gur pRswid ] ] jpu ] Awid scu jugwid scu ] hY BI scu nwnk

我希望输出如下图所示

这是一本使用区域字体(Gurumukhi)的锡克教圣书,我想制作一个文本的xml文件,使用xml解析在我的应用程序中显示。但问题是,当我将这种字体粘贴到xml文件中时,它会转换成一些字母和符号,如下所示

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
jpujI swihb
siq nwmu krqw purKu inrBau inrvYru
Akwl mUriq AjUnI sYBM gur pRswid]
][日本新闻大学]
Awid scu JGWID scu]
hY BI scu nwnk hosI BI scu]1]
socY soic n hoveI jy Soc 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]
胡克米·霍温
我已经在asset文件夹中放置了一个Gurumukhi字体文件,并使用了下面的代码,效果很好

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")
Typeface tf=Typeface.createFromAsset(getAssets(),
“fonts/bulara_5.ttf”);
textView=(textView)findViewById(R.id.textView1);
textView.setTypeface(tf);
setMovementMethod(新的ScrollingMovementMethod());
textView.setText(“siq nwmu krqw purKu inrBau inrvYru”)

通过这种方式,文本视图中的文本将转换为Gurumukhi,但是
如何为其中的此类文本创建Xml文件
。或者
给我一些好的建议,哪种方法更适合处理这种类型的应用程序和文本
。我必须在一个应用程序中显示4-5本圣经,每本都有20-25页。感谢您的帮助

您似乎正在尝试使用一种专用编码的8位字体来处理古木基字母,即代码范围为0到255的字体,每个数字根据某种字体相关约定映射到一个字符,而不是通过任何标准编码

考虑改用Unicode(UTF-8)和Unicode编码字体。

更新 因为您想通过XML使用 您的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="@string/book"
        android:textAppearance="?android:attr/textAppearanceLarge" 

        />

</LinearLayout>
现在是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>

活动

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");
    }
}
package com.nannu;
导入android.app.Activity;
导入android.os.Bundle;
公共类NanDempoActivity扩展活动{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
NanTV nan=(NanTV)findViewById(R.id.textView1);
nan.setText("[jpu]Awid scu jugwid scu]hY BI scu nwnk hosI BI scu]1]socY soic n hoveI jy Social vwr]cupY cup n hoveI jy lwie lwie Rwie lwie lwie JW lwie LWR]BuiKAw Buik n auqrI jy NW purIAw Bwr]shs Isaw Xpw lK Hwi ikv Sicawy ikv jy jy Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie Kwie K例如:1)hukmI hovin(即“hukmu n kihAw jweI”)hukmI hovin(即“hukmI hovin”);
}
}

我在xml中做了一些更改,请记住需要更改

我在资产文件夹中创建了一个data.xml,xml如下所示

    <?xml version="1.0" encoding="UTF-8"?>
    <book1>
    <page1>&#60;&#62; 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 jIA hukim imlY vifAweI ]
  hukmI auqmu nIcu hukim iliK duK suK pweIAih ]
  ieknw hukmI bKsIs ieik hukmI sdw BvweIAih ]
  hukmY AMdir sBu ko bwhir hukm n koie ]
  nwnk hukmY jy buJY q haumY khY n koie ]2]
  gwvY ko qwxu hovY iksY qwxu ]</page1>
  </book1>
  import java.io.BufferedInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.StringReader;
  import java.io.UnsupportedEncodingException;
  import java.net.MalformedURLException;

  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;

  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;



  public class StudyParser {
public StudyParser() {

}

public final static Document XMLfromString(String xml){
     Document doc = null;

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setCoalescing(true);
            try {

          DocumentBuilder db = dbf.newDocumentBuilder();

          InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xml));
              doc = db.parse(is); 

        } catch (ParserConfigurationException e) {
          System.out.println("XML parse error: " + e.getMessage());
          return null;
        } catch (SAXException e) {
          System.out.println("Wrong XML file structure: " + e.getMessage());
                return null;
        } catch (IOException e) {
          System.out.println("I/O exeption: " + e.getMessage());
          return null;
        }

            return doc;

  }
public static String getXMLstring(String xml){   
      String line = null;

      try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(xml);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);

      } catch (UnsupportedEncodingException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (MalformedURLException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (IOException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      }

      return line;

  }
public static String getXML(InputStream is)throws IOException {

    BufferedInputStream bis = new BufferedInputStream(is);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int result = bis.read();
    while(result != -1) {
      byte b = (byte)result;
      buf.write(b);
      result = bis.read();
    }        
    return buf.toString();
}
public final static String getElementValue( Node elem ) {
       Node kid;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
                   if( kid.getNodeType() == Node.TEXT_NODE  ){
                       return kid.getNodeValue();
                   }

               }
           }
       }
       return "";
   }
 public static int numResults(Document doc){    
        Node results = doc.getDocumentElement();
        int res = -1;

        try{
          res = Integer.valueOf(results.getAttributes().getNamedItem("Categories").getNodeValue());
        }catch(Exception e ){
          res = -1;
        }

        return res;
      }

      public static String getValue(Element item, String str) {    
        NodeList n = item.getElementsByTagName(str);    
        return StudyParser.getElementValue(n.item(0));
      }


}

Namastey,如果你想这样做,你需要扩展你的文本视图:)@iNan Namastey,我如何扩展该文本视图,以及如何将该类型的文本放入xml文件。还有其他方法吗?是的,我会帮助你,请提供我下载字体的链接??你可以从这里下载Bulara字体zipfile@NareshSharma在那上面第页,链接“下载bulara.zip”指向只包含index.html的zip文件。@NareshSharma,显然字体不是Unicode编码的,而是特定于字体的编码。你没有看到我问题的最后几行,因为我解释说我可以像你那样完成。但是每本书都有20-25页,所以我无法在不同的textview上设置这样的文本。因此,我想制作一个xml文件,从中获取文本,或者请给我其他更好的方法。否则,你的工作是值得赞赏的。感谢你的帮助和回答。请告诉我方法。我已经投票了你的答案,感谢你的努力。只要给我一个建议,我如何显示其他页面的文本。或者我必须使用更多这样的文本视图,并在该视图上设置文本,或者我应该如何在同一文本视图上设置不同的文本。你可以使用
添加滚动条,如果你有更多的页面,你可以使用
setText
方法动态添加它们,或者添加单独的活动。最好的方法是在中为每个页面添加一个单独的记录ode>string.xml
。那么如何在同一文本视图上反复显示string.xml中的不同文本。添加一个带有
onclicklistener
的按钮,然后使用扩展的
textview
setText
并使用
setText(getResources().getString(R.string.page1))
然后使用第2页等
    <?xml version="1.0" encoding="UTF-8"?>
    <book1>
    <page1>&#60;&#62; 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 jIA hukim imlY vifAweI ]
  hukmI auqmu nIcu hukim iliK duK suK pweIAih ]
  ieknw hukmI bKsIs ieik hukmI sdw BvweIAih ]
  hukmY AMdir sBu ko bwhir hukm n koie ]
  nwnk hukmY jy buJY q haumY khY n koie ]2]
  gwvY ko qwxu hovY iksY qwxu ]</page1>
  </book1>
  import java.io.BufferedInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.StringReader;
  import java.io.UnsupportedEncodingException;
  import java.net.MalformedURLException;

  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;

  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;



  public class StudyParser {
public StudyParser() {

}

public final static Document XMLfromString(String xml){
     Document doc = null;

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setCoalescing(true);
            try {

          DocumentBuilder db = dbf.newDocumentBuilder();

          InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xml));
              doc = db.parse(is); 

        } catch (ParserConfigurationException e) {
          System.out.println("XML parse error: " + e.getMessage());
          return null;
        } catch (SAXException e) {
          System.out.println("Wrong XML file structure: " + e.getMessage());
                return null;
        } catch (IOException e) {
          System.out.println("I/O exeption: " + e.getMessage());
          return null;
        }

            return doc;

  }
public static String getXMLstring(String xml){   
      String line = null;

      try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(xml);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);

      } catch (UnsupportedEncodingException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (MalformedURLException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (IOException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      }

      return line;

  }
public static String getXML(InputStream is)throws IOException {

    BufferedInputStream bis = new BufferedInputStream(is);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int result = bis.read();
    while(result != -1) {
      byte b = (byte)result;
      buf.write(b);
      result = bis.read();
    }        
    return buf.toString();
}
public final static String getElementValue( Node elem ) {
       Node kid;
       if( elem != null){
           if (elem.hasChildNodes()){
               for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
                   if( kid.getNodeType() == Node.TEXT_NODE  ){
                       return kid.getNodeValue();
                   }

               }
           }
       }
       return "";
   }
 public static int numResults(Document doc){    
        Node results = doc.getDocumentElement();
        int res = -1;

        try{
          res = Integer.valueOf(results.getAttributes().getNamedItem("Categories").getNodeValue());
        }catch(Exception e ){
          res = -1;
        }

        return res;
      }

      public static String getValue(Element item, String str) {    
        NodeList n = item.getElementsByTagName(str);    
        return StudyParser.getElementValue(n.item(0));
      }


}
 TextView txt;
 try{
 txt = (TextView)findViewById(R.id.tv); 
 String   xml= StudyParser.getXML(getAssets().open("data.xml"));    

   Document doc = StudyParser.XMLfromString(xml);
  NodeList n = doc.getElementsByTagName("book1");
 Element eid = (Element) n.item(0);
String Js=StudyParser.getValue(eid, "page1");
 Typeface tf = Typeface.createFromAsset(getAssets(),"bulara_5.ttf");
 txt.setTypeface(tf);
 txt.setText(Js);
   }catch(Exception e){
 Log.e("error",e.toString());
   }