1

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 enter image description here

Akshay Takkar
  • 500
  • 1
  • 7
  • 21
  • have a look at http://stackoverflow.com/questions/15210548/how-to-use-a-icons-and-symbols-from-font-awesome-on-native-android-application – Frame91 Jun 12 '14 at 12:22
  • That's what I did. But the icon gets added as a value in the edittext field – Akshay Takkar Jun 12 '14 at 12:24
  • because it's a font, not an Image. You can use two textviews in a linearlayout to get the desired result, but you can't use an Icon as a font and simultaenously using it as a textfield – Frame91 Jun 12 '14 at 12:25
  • I want the icon to be placed in the textfield like shown here http://reachout.herokuapp.com/users/sign_in . Any idea how do I do that? – Akshay Takkar Jun 12 '14 at 12:26
  • sorry, i'm not able to open this link from my workplace. Can you upload the Image to your post so I can have a look? – Frame91 Jun 12 '14 at 12:28
  • @Frame91 Added the screenshot. Please have a look – Akshay Takkar Jun 12 '14 at 12:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55501/discussion-between-akshay-takkar-and-frame91). – Akshay Takkar Jun 12 '14 at 12:42

3 Answers3

4

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

Dodge
  • 8,047
  • 2
  • 30
  • 45
1

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);
Christopher Smit
  • 953
  • 11
  • 27
0

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491