【发布时间】:2014-11-06 14:53:07
【问题描述】:
我正在尝试在我的 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;
}
字符串.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");
}
【问题讨论】:
-
fontFamily是在哪里定义的?另请注意,您正在为 imgIcon 分配 txtTitle 的 相同值:imgIcon.setText(navDrawerItems.get(position).getTitle()); txtTitle.setText(navDrawerItems.get(position).getTitle()); -
@funkystein 它在我的列表适配器的构造函数中初始化
-
你能展示一下缺失的部分吗?
-
@funkystein 我更新了我的问题
-
我可能会在 onCreate() 或 onCreateView() 方法中移动这个
fontFamily = Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome.ttf");。并考虑我第一条评论的第二部分。
标签: android unicode font-awesome