我在我的Android应用程序中使用了旁遮普字体anmollipi。当我使用buffere阅读器从文件中读取它时它工作正常,但我无法在ListView中显示旁遮普语。任何建议
答案 0 :(得分:0)
像这样创建一个自定义适配器 -
public class CustomUsersAdapter extends ArrayAdapter<User> {
public CustomUsersAdapter(Context context, ArrayList<User> users) {
super(context, 0, users);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
User user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false);
}
// Lookup view for data population
TextView tvName = (TextView) convertView.findViewById(R.id.title);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
tvName.setTypeface(type);
// Populate the data into the template view using the data object
tvName.setText(user.name);
// Return the completed view to render on screen
return convertView;
}
}
这里我们使用了item_user
,它是每行的布局。像这样 -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:paddingBottom="10dp"
android:textColor="#CC0033"
android:textSize="16dp" />
</RelativeLayout>
我们使用此代码设置字体
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
txtView.setTypeface(type);
你必须将你的字体文件放在名为&#34; fonts&#34;的新文件夹中。