So far I've used the following code to add the icon
EditText email = (EditText) findViewById(R.id.email);
Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome-webfont.ttf" );
email.setTypeface(font);
But the icon gets added as a value of the edittext field. Whereas I want the icon to appear at the left. I also know about the android:drawableLeft attribute but it requires I drawable resource i.e a jpeg and not a ttf. How can I solve this problem. Thanks
for font awesome in android apps i suggest https://github.com/JoanZapata/android-iconify
but that would not fix your issue as the icon still would be a part of the value.
to avoid this you might want to use https://github.com/DayS/EnhancedEditText which uses the android-iconify library to achieve what you want :)
good luck
Checkout the following Stack Overflow post.
How to use icon from font file as a drawable in Android
Then use it:
mEmailView = findViewById(R.id.login_email);
FontDrawable user = new FontDrawable(this, getString(R.string.fa_fa_user_circle_o), iconFont);
user.sizePx((int)mEmailView.getTextSize());
user.colorRes(R.color.white);
mEmailView.setCompoundDrawablesWithIntrinsicBounds(user, null, null, null);
How can I solve this problem.
Use a PNG or JPEG.
Or, create (or find) a Drawable that renders text in a font, and use setCompoundDrawables() to associate such a drawable with your EditText at runtime.
Related
I am trying to use a custom font in a password hint field in Android Studio.
After I set the Edit Text as inputType="textPassword" in XML, the font changes to a different from the one I've chosen. All the other Edit Texts have the correct custom font.
I've tried following this solution in java code (replaced Typeface.DEFAULT with R.font.my_font) but nothing happened
EditText password = (EditText) findViewById(R.id.register_password_text);
password.setTypeface(R.font.my_font);
password.setTransformationMethod(new PasswordTransformationMethod());
I've also tried this solution with no success
Typeface cache = edtPassword.getTypeface();
edtPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
edtPassword.setTypeface(cache);
Any ideas on what to try or what might be missing in these solutions?
PS: I'm using montserrat_regular font
Its happening because you are passing the id of the font in
password.setTypeface(R.font.my_font) not the TypeFace Object. You need to pass TypeFace object in setTypeFace() method , so to make TypeFace object from your font resource Id just add the code
Typeface typeface = ResourcesCompat.getFont(this, R.font.my_font);
password.setTypeface(typeface);
I think this should work.
I have a simple TextView, where I put a string like that: "Curăță corect urechile copilașului tău!". But I see the string on display like this "Cură ă corect urechile copilașului tău!" - just space between chars, where must be a "ț" symbol.
I checked the string in TextView by TextView.getText(), and I get my original string.
This is a screenshot, also the same problem in first title:
Try to set text in TextView using HTML. I hope this will work and may help you out.
myTextView.setText(Html.fromHtml("your_string"));
There is still space for the letters, so perhaps it's an issue with the styling.
Change the style to default, do the letters show up?
Try adding a shadow to the textviews and see if the shadow exists (maybe the letters are somehow transparent, or the same color as the background?)
It is more related to a font issue, default Android font doesn't support some characters. You need to try from a different font.
You can try from the following (but I think its not free)
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=FontDownloads
I have a TextView which contains just one letter. The size of the text is calibrated so that the letter occupies entire TextView area. Now one of my users reported a problem that the letter does not fit properly into the TextView. From the attached screenshot I can see that she uses some kind of custom font on her Samsung S4 device. I am sure that's the problem. Here are some snapshots:
Custom font in a TextView over ImageView:
Custom font in the Status Bar:
Distorted letter N in my TextView:
Is there any way to make a TextView use standard android font ignoring any custom fonts that users applies? How can I install custom fonts on the emulator or Sony phone (do not have Samsung) and replicate the behavior?
Yes you can set custom fonts to your app. Make use TypeFace class.
Create a folder called fonts under assets folder and place all your fonts in it (Font format ttc or ttf. Folder name can be anything)
Within you onCreate method add the below code.
TextView mytextview= (TextView) findViewById(R.id.text_view_id);
// Loading Font Face. Replace with your font file name
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/your_custom_font.ttf");
// Applying font
mytextview.setTypeface(tf);
Similar way you can have as many as TypeFace you require and also use the same TypeFace declared on as many as TextView you want.
This tutorial below very well explains your requirement and also provides screenshot for better assistance.
http://www.androidhive.info/2012/02/android-using-external-fonts/
Also kindly note that TypeFace has a lot of other options that you can play around with. You can refer the android docs to get an idea about them.
I hope it helped you.
Thanks!!
My advise:
Create a subfolder in your asset folder called fonts.
Put there the fonts you want to use (for example ttc, or ttf) Set
your TextView typeface. For example:
yourTextView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/yourFont.ttc"));
I hope it helps!!
I know how to change the font of a TextView to my own font:
catTextView = (TextView)findViewById(R.id.CatText);
catTextView.setTypeface(Typeface.createFromAsset(getAssets(), "my_font_in_assets"));
However at a point during the app execution, I would like to set it back to the default font. I don't want to hardcode the font (write "Droid Sans") since the default font could change in future versions of Android (I think it actually did in ICS).
Is there any way to get the default font name of a TextView, and set it back to this after changing it?
Also, can I be sure the default font will always be able to show Russian or Japanese characters?
Thanks!
Use setTypeface(Typeface.SANS_SERIF) on a TextView
Have you tried calling getTypeface() in your TextView before you change it and store the result somewhere?
http://developer.android.com/reference/android/widget/TextView.html#getTypeface()
Use this:
textView.setTypeface(null);
You can restore default typeface using
Typeface.defaultFromStyle(R.style.YourTheme);
How can I change the default font for keys of keyboard I am writing in android (Eclipse)?
Thank you
One solution is to use keboardView.java instead of android.inputmethodservice.KeyboardView.
You also need to change paint.setTypeface(Typeface.DEFAULT_BOLD) to paint.setTypeface(my font) and you must add attrs.xml to your project.
I found an answer : Implemented onDraw...
#Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
try{
onBufferDraw();
}catch(Exception ex){
}
if (mBuffer!=null)
canvas.drawBitmap(mBuffer, 0, 0, null);
}
if you are thinking to change the font style of android custom keyboard keys font style with an external .ttf font style then you can check my answer at a link
answer to change the font style of key label of android custom keyboard and also to change the font style throughout the android application
this answer is verified by me personally so you can trust and check this.
Well that's a very broad question. I can tell you how to set a different Typeface; how you work that into your keyboard application is up to you.
Place a font (.ttf or .otf) into your assets folder, and use the following code (assuming a font called "myfont.ttf" and a TextView with an id of "key"):
Typeface myFont = Typeface.createFromAsset(getAssets(), "myfont.ttf");
TextView key = (TextView)findViewById(R.id.key);
key.setTypeface(myFont);
Reminder: Don't forget to check the license for the font you are using. Most do not allow redistribution without compensation. One freely licensed font you can use is Bitstream Vera Sans.