Android - Set font in other language - java

How can I set custom font to editText in Android? I use this code
etPlace = (EditText)findViewById(R.id.editTextPlace);
etPlace.setTypeface(tf);
It can work with English language. But if I type in Thai language, it will become to HEX. I tried to remove setTypeface code but it can't solve. Anyone can suggest me?
This is example picture of my app

You must use some Unicode font that support your wanted language in the setTypeface method. Like Arial Unicode MS.

You should create a class that return EditText Object with font you want to support.
EditText public SetLanguage(EditText tv,string type)
{
EditText newtv = tv;
Typeface tf;
switch(type)
{
case "en":
tf = Typeface.createFromAsset(this.getAssets(),"en.ttf");
break;
case "thai":
tf = Typeface.createFromAsset(this.getAssets(),"thai.ttf");
break;
// up so on
}
newtv.setTypeface(tf);
return newtv;
}
// and call it any where..
EditText etPlace = (EditText ) findViewById(R.id.textView2);
etPlace = classobj.SetLanguage(textView1,"thai");
//assign string of text to it

Related

How to make SWT button Text BOLD

I am creating a checkbox button with text in SWT.
org.eclipse.swt.widgets.Button button= new Button(composite, SWT.CHECK);
button.setText(Messages.AnswerDialog_answer);
button.setSelection(true);
In messages.properties, I have the value
AnswerDialog_answer=Answer
How can i show the text(ie. Answer) of this button in BOLD?
You can convert the currently assigned font for the button to be bold using something like:
FontData [] data = button.getFont().getFontData();
for (FontData datum : data) {
datum.setStyle(SWT.BOLD);
}
Font boldFont = new Font(button.getDisplay(), data);
button.setFont(boldFont);
Note: You must call boldFont.dispose() when you are done with the font (such as when the dialog closes).
I'm not sure that all platforms support changing the button font. The above code works on macOS.

having trouble with arabic font rendering correctly android app

My android app is not displaying the arabic font correctly on the view that displays the radio player and the text. I get symbols in the arabic text (percent sings, copyright and registered trade mark symbols, double greater thann signs, +/- sign, double commas ... ALL mixed with arabaic characters).
Here is a snippet from the java class file:
private void setTypeFace(){
int os_version = ((MiraathRadio)getApplication()).os_version;
if(os_version < 9){
Typeface tf = Typeface.createFromAsset(getAssets(), fontpath);
audioTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathFroyo2);
stationTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathmotlak);
listenerNomber.setTypeface(tf);
}
else {
Typeface tf = Typeface.createFromAsset(getAssets(), fontpath2);
audioTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathArabic2);
stationTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathmotlak);
listenerNomber.setTypeface(tf);
}
}
I have installed Tahoma, Froyo, and mcs_jf2 fonts (all TTF) and still it will not render correctly.
I have tried to use a Arabizer and Farsi class file to connect, but to now avail.
I have a screen shot of the problem if anyone wants to see it.
What am I doing wrong???
Any help would be greatly appreciated!!
Thanks!!
ironmantis7x
I am posting the code where I am setting the text:
private void setTypeFace(){
int os_version = ((MiraathRadio)getApplication()).os_version;
if(os_version < 9){
Typeface tf = Typeface.createFromAsset(getAssets(), fontpath);
audioTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathFroyo2);
stationTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathmotlak);
listenerNomber.setTypeface(tf);
}
else {
Typeface tf = Typeface.createFromAsset(getAssets(), fontpathArabic3);
audioTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathArabic3);
stationTitle.setTypeface(tf);
tf = Typeface.createFromAsset(getAssets(), fontpathArabic3);
listenerNomber.setTypeface(tf);
I am lost here. Any pointers and help would be great.
ironmantis7x
Alhamdulillah!!!
Found the issue!!!
The encoding was wrong ...
The previous developer put "windows-1256" as the encoding type.
I changed it to "utf-8" and it works just fine!!!
Thanks everyone for all your help!!!

Android TextView horizontal scroll does not work

I read some thread in this topic, but I have not found the solution.
I would like to use the scrollHorizontally attribute on a TextView, but from Java code.
Here's what I tried:
nameTextView = new TextView(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
nameTextView.setId(R.id.header_text_id);
nameTextView.setGravity(Gravity.CENTER | Gravity.LEFT);
nameTextView.setSingleLine();
nameTextView.setHorizontallyScrolling(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
nameTextView.setFocusableInTouchMode(true);
nameTextView.setMarqueeRepeatLimit(-1);
nameTextView.setFocusable(true);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/robotocondensed.ttf");
nameTextView.setTypeface(tf);
nameTextView.setTextColor(getResources().getColor(android.R.color.white));
I set the text later. The text does not scroll, what can be the problem here?
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
Then set:
yourTextView.setMovementMethod(new ScrollingMovementMethod())
excelent article about how to make an horizontal scrollable textview in android, It works!!!
http://gabrielbl.com/2013/08/09/android-auto-horizontal-scrolling-marquee-textview/

Android html.form html

I'd like to read html tags to a TextView, so I have done this:
titolo = (TextView) this.findViewById(R.articolo.titolo);
testo = (TextView) this.findViewById(R.articolo.testo);
titolo.setText(db.getTitolo());
testo.setText(db.getTesto());
testo.setText(Html.fromHtml(testo));
But i have an errore here: testo.setText(Html.fromHtml(testo)); Why?
This application retrieves data from a database so I hope that if I write into the database, for example hello this is formatted as bold using html.fromhtml
public static Spanned fromHtml (String source)
Returns displayable styled text from the provided HTML string. Any tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.
This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
More info #
http://developer.android.com/reference/android/text/Html.html
This
testo = (TextView) this.findViewById(R.articolo.testo); // textview initialized
This
testo.setText(Html.fromHtml(testo)); // wrong
fromHtml takes a string as a argument
It should be
testo.setText(Html.fromHtml("myhtmlString"));
Example :
String s ="<b>"+"Hello"+"</b>";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(Html.fromHtml(s));
In your example you're sending TextView to fromHtml and you should deliver String variable. That String could contain HTML tags.
TextView testo = (TextView) findViewById(R.articolo.testo);
String formattedText = "This is <b>bold</b>";
testo.setText(Html.fromHtml(formattedText));
Of course you could get String from DB. I don't know how works your getTesto() method, but if it returns String you could write:
TextView testo = (TextView) findViewById(R.articolo.testo);
String formattedText = db.getTesto();
testo.setText(Html.fromHtml(formattedText));

Clear the textview and add the new textview while click the each category

In my Android application I have to display article title on corresponding category.
I wish to display the output in following format:
Languages Programming --- Category name on Horizontal listview
If I have to click Languages which means getting the article title for that selected category alone and displaying on Horizontal listview.
Languages Programming
Tamil Engilsh Hindi Telugu
If I have to click Programming means need to display the :
Languages Programming
Java C C++
Now my current status is :
I have to run the app and click Languages which means getting the output is :
Languages Programming
Tamil English Hindi
After that I have to click Programming means getting the output is :
Languages Programming
Tamil English Hindi
What's wrong in my code? Why am getting the same output on my app screen?
But i got the correct article titles on my console window. I have facing problem only on my app screen only..
What's wrong in my code ... please give me solution for these ...
public void updateDetail(String categorytitle,int object) {
lblName.setText(categorytitle);
System.out.println("The Category name is "+categorytitle);
String strI = Integer.toString(object+1);
String[] stockArr = new String[Appscontent.Sub_arraylist.size()];
stockArr = Appscontent.Sub_arraylist.toArray(stockArr);
for (String s : stockArr)
{
if (s.startsWith(strI))
{
String _Substring;
_Substring = s.substring(1);
Appscontent.Sub_arraylisttwo.add(_Substring);
}
}
//pass the article title
hSroll = new HorizontalScrollView(getActivity());
lLayout = new LinearLayout(getActivity());
lLayout.setOrientation(LinearLayout.HORIZONTAL);
lLayout.setLayoutParams(lLayoutLayoutParams);
lLayout.setHorizontalScrollBarEnabled(true);
lLayout.setGravity(Gravity.CENTER);
for(int j = 0; j < Appscontent.Sub_arraylisttwo.size(); j++)
{
LinearLayout ly = new LinearLayout(getActivity());
ly.setOrientation(LinearLayout.VERTICAL);
ly.setBackgroundColor(Color.parseColor("#666666"));
ly.setLayoutParams(articleLayoutParams);
ly.setPadding(1, 1, 1, 1);
ly.setOnClickListener(mArticleClick);
ly.setId(position);
position++;
TextView tv = new TextView(getActivity());
tv.setHorizontallyScrolling(false);
tv.setTextColor(Color.parseColor("#FFFFFF"));
tv.setText(Appscontent.Sub_arraylisttwo.get(j));
System.out.println("The article title is "+Appscontent.Sub_arraylisttwo.get(j));
ly.addView(tv);
lLayout.addView(ly);
}
int num = Integer.parseInt(strI);
strI = String.valueOf(num = num + 1);
Appscontent.Sub_arraylisttwo.clear();
Appscontent.Sub_arraylistdessub.clear();
Appscontent.Sub_arraylistimagesub.clear();
Appscontent.Sub_arraylistcontentsub.clear();
Appscontent.Sub_arraylistvideosub.clear();
hSroll.addView(lLayout);
verticalLayout.addView(hSroll);
}
Please review my code and give me solution for these...am getting the correct output on my console window.But i didn't get the output on my android app screen...
EDIT:
My consolw output is :
When clicked Languages means
The Category name is Languages
The article title is Tamil
The article title is English
The article title is Hindi
The article title is Telugu
Afterthat i have clicked Programming means
The Category name is Programming
The article title is Java
The article title is c
The article title is C++

Categories