我试图在我的Android应用程序中使用Font Awesome图标。我存储了我想在strings.xml文件中使用的各种图标的unicode但是当我运行我的应用程序时我得到了这个
我做错了什么?
码
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}
TextView imgIcon = (TextView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
TextView txtCount = (TextView) convertView.findViewById(R.id.lock);
imgIcon.setTypeface(fontFamily);
imgIcon.setText(navDrawerItems.get(position).getTitle());
txtTitle.setText(navDrawerItems.get(position).getTitle());
// displaying count
// check whether it set visible or not
if (navDrawerItems.get(position).getCounterVisibility()) {
txtCount.setText(navDrawerItems.get(position).getCount());
} else {
// hide the counter view
txtCount.setVisibility(View.GONE);
}
return convertView;
}
的strings.xml
<string-array name="nav_drawer_items">
<item>Home</item>
<item>Register</item>
<item>Create Pattern</item>
<item>Forgot Login Details</item>
<item>Check Service</item>
<item>Reset Data</item>
<item>Settings</item>
</string-array>
<array name="nav_drawer_icons">
<item>\uf015</item>
<item>\uf0c7</item>
<item>\uf00a</item>
<item>\uf1da</item>
<item>\uf00c</item>
<item>\uf021</item>
<item>\uf013</item>
</array>
初始化字体真棒的构造函数
public NavDrawerListAdapter(Context context,
ArrayList<NavDrawerItem> navDrawerItems) {
this.context = context;
this.navDrawerItems = navDrawerItems;
fontFamily = Typeface.createFromAsset(context.getAssets(),
"fonts/fontawesome.ttf");
}
答案 0 :(得分:0)
我最近使用android-type-textview lib(https://github.com/ragunathjawahar/android-typeface-textview)将Fontello(http://fontello.com/)图标添加到我的应用程序中。下载lib,将您需要的字体添加到assets / fonts文件夹中,添加
xmlns:geekui="http://schemas.android.com/apk/res-auto"
按照github页面的说明进行布局,并使用类似的代码替换布局文件中的TextView:
<com.mobsandgeeks.ui.TypefaceTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
geekui:customTypeface="fonts/YOUR_FONT.ttf" />
如果您不想使用第三方库,您将能够查看代码(它非常简单)以了解如何以正确的方式处理字体。