How can I convert a Unicode string like
"\u0646\u0627\u0645"
to a human-readable string that I can put in a TextView?
No need to do anything more than this
TextView text = (TextView) findViewById(R.id.yourTextView);
text.setText("\u0646\u0627\u0645");
Related
I am using this emoji library
https://github.com/hani-momanii/SuperNova-Emoji
This library has a custom textview which can render emojis. How do I set text of that textview so it displays emojis ?
For example I tried this and it did not work :
String happy = " Feeling happy U+1F601 ";
emojitextview.setText(happy);
Switch out the 'U+' for '0x':
int unicode = 0x1F601;
String happy = "Feeling happy " + getEmojiByUnicode(unicode);
And put it through a helper function:
public String getEmojiByUnicode(int unicode){
return new String(Character.toChars(unicode));
}
p.s. if it still doesn't work, you may have to set the textView to use a typeface that supports emoji characters
from:
how set emoji by unicode in android textview
I have set text in text view
TextView text = view.FindViewById<TextView>(Resource.Id.details);
text.SetText(_text, TextView.BufferType.Normal);
it sets unknown characters when displays
how to write unicode characters correct ?
must be text like this
Try this,
text.setText(Html.fromHtml(_text));
Define your characters/string, which you want to display, in res/values/strings.xml. Load it in textview like
strings.xml
<string name="unicodechar">my unicode char is here</string>
in Java:
String _text = context.getResources().getString(R.string.unicodechar);
textview.settext(_text);
Try using a method like this to convert the string:
public String encodeUTF(String str) throws UnsupportedEncodingException {
byte[] utf8Bytes = str.getBytes("UTF-8");
String encodedStr = new String(utf8Bytes, "UTF-8");
return encodedStr;
}
Normally it will either need to be UTF-8 or ISO 8859-1
Use a font like DejaVuSans.ttf. Copy this in assets folder. Then set the typeface of the text view as below. After this try setting the text.
tv=(TextView)findViewById(R.id.textView1);
Typeface font= Typeface.createFromAsset(getAssets(), "DejaVuSans.ttf");
tv.setTypeface(font);
everyone. I am trying to set the color of a few words in a string using spannablestring.But for some reason I cant get the color of the string to change.
I have attached the relevant code
String color = "some string"
SpannableString span_color= new SpannableString(color);
span_color.setSpan(new ForegroundColorSpan(Color.GREEN),0,11,0);
String print = "This is the whole string"+span_color;
TextView textview = (TextView) findViewById(R.id.text);
textview.setText(reminder);
In the Text View, I want the "This is the whole string" to be in the default color and the "some string" to be in green. but this is not happening.I am getting the entire string in the default color.I seem to be missing something important , but I cant figure out what .
Any suggestion?
Using "+" operator you get just string, not SpannableString. You should do something like this:
String color = "This is the whole string, color string";
SpannableString spanColor = new SpannableString(color);
spanColor.setSpan(new ForegroundColorSpan(Color.GREEN), color.indexOf("color string"), color.length(), 0);
TextView textview = (TextView) findViewById(R.id.text);
textview.setText(spanColor);
I'm new to android and I'm trying to replace a character from bold style at a specific character in a arraylist string. What I'm doing is:
String myName = "76492";
This is my search string and i want to search this string in to the arraylist then i want to bold those character when getting on the arraylist.Arraylist string is 78758,3660,56798,6514,90679.
TextView txtf = (TextView)findViewById(R.id.textView4);
TextView txtS = (TextView) findViewById(R.id.textView5);
TextView txtT = (TextView)findViewById(R.id.textView6);
TextView txt1 = (TextView) findViewById(R.id.textView9);
TextView txt2 = (TextView) findViewById(R.id.textView13);
String str= myName.replaceAll("6", "<b>6</b>");
Spanned text = Html.fromHtml(str);
txtf.setText(text);
txtS.setText(text);
txtT.setText(text);
txt1.setText(text);
txt2.setText(text);
But this is replace all Textview String by the 76492 string with match charater bold style. 1879 search string this is replace old string but i donot want this type replace .iI want only specific position character change in bold style
<style name="boldText">
<item name="android:textStyle">bold</item>
</style>
Paste this code snippet in your style.xml which is in valuse folder under layout.
txtf.setTextAppearance(this, R.style.boldText);
This line of code is for your text view appear as a bold.
Use spans. Then you can specify parts of your string and assign any format or color you want. Have a look at this.
Edit: For clarification: With spans you don't replace the characters. Use some string method to find the position of the characters you want to change to bold and create a span on these positions and assign bold format to that span.
I need to print the below string which is in Arabic on TextView in Android. It is printing good but when the Arabic text and digits falls in a same string, Android put the digit at end!
here is my code
String str = "مقر 44";
TextView textView = (TextView)findViewById(R.id.test);
textView.setText(str);
Here is the output
you can try with this workaround
String str = "44 "+"مقر ";
TextView textView = (TextView)findViewById(R.id.txt_title);
textView.setText(str);
its not Android who put digit at the end, its because of Arabic writing standard