Hindi text does not display properly in android

I am working on an application where I have to show the text received from the server response in textview . The text can be in English or Hindi . In the case of Hindi, some letters are replaced by question marks (?) . What is the problem? This is how I set my text. Android version 6 . Font Type - Proxima Nova Alt Regular

  for (int i = 0; i < 3; i++) { viewHolder.lines[i].setText(poem.lines[i].lineText); } 

enter image description here

+7
android unicode utf-8 character-encoding iso-8859-1
source share
4 answers

From your question, it seems that some letters are being processed properly, while others are not. This is obviously a font compatibility issue. Download a new font for your version of Android if you want to use your own font.

However, on many newer Android devices (especially Android 6 and later), Hindi is supported by default. Therefore, in this case, just check the Settings --> Language & input your phone. If Hindi is supported, then just change the Locale application to Hindi and it should work.

 Configuration.Locale = new Locale("hi", "IN"); 
+2
source share

Create a font folder in the application resource folder and place your custom fonts there. And then set the fontFamily attribute to the TextView, as shown below:

  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="NameOfYourCustomFonts"/> 
-one
source share

Download Hindi From Font: http://fonts.webtoolhub.com/font-n17979-kruti-dev-010.aspx

put this font in the "assets" folder: app / src / main / assets / kruti-dev-010.ttf

 Typeface hindiFont = Typeface.createFromAsset(MainActivity.this.getAssets(), "fonts/Kruti_Dev_010.ttf"); txtFont.setTypeface(hindiFont); txtFont.setText("एनडीटीवी इंडिया : हिन्दी समाचार की आधिकारिक वेबसाइट"); 
-one
source share

Try converting the string to UTF-8 as

 viewHolder.lines[i].setText(URLDecoder.decode(poem.lines[i].lineText,"UTF-8"); 
-one
source share

All Articles