问题描述
我想在我的Android应用程序中使用Font Awesome的图标集.我有一些TextView
来设置这些图标.我不想使用任何PNG图片.我的Textview就是这样->
<TextView
android:id="@+id/userLogin"
android:text="Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
否,我想在立即登录文本之前放置一个图标.该怎么做?
您可以按照以下 首先从此处下载fontawesome.ttf.并将文件放在 asset/fontawesome.ttf 中. 然后创建一个 现在您可以根据需要使用Fontawesome类,并按照 cheatsheet.来获取图标的Unicode. 因此,您的文本视图将是这样. I want to use Font Awesome's icon set in my android application. I have some No, I want to put a icon before the text Login Now. How to do that ? You can follow this answer. First Download the fontawesome.ttf from here. And put the file in asset/fontawesome.ttf . Then Make a now you can use the Fontawesome class as your need and also follow the cheatsheet. to get your icon's Unicode. So, your textview will be like this . 这篇关于如何在Android应用程序中使用Font Awesome图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!FontAwesome
类,它实际上以这种方式表示FontAwesome
的文本视图. public class FontAwesome extends TextView {
public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public FontAwesome(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FontAwesome(Context context) {
super(context);
init();
}
private void init() {
//Font name should not contain "/".
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"fontawesome.ttf");
setTypeface(tf);
}
}
<PACKAGE_NAME.Fontawesome
android:id="@+id/userLogin"
android:text=" Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
TextView
to set those icons. I don't want to use any png image. My Textview is like this -><TextView
android:id="@+id/userLogin"
android:text="Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
FontAwesome
class which actually represent the textview of FontAwesome
like this way. public class FontAwesome extends TextView {
public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public FontAwesome(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FontAwesome(Context context) {
super(context);
init();
}
private void init() {
//Font name should not contain "/".
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"fontawesome.ttf");
setTypeface(tf);
}
}
<PACKAGE_NAME.Fontawesome
android:id="@+id/userLogin"
android:text=" Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />