如何在Android的ListView中用旁遮普语写作



我在我的Android应用程序中使用了旁遮普语字体Anmollipi。 当我使用 Buffere 阅读器从文件中读取它时,它运行良好,但我无法在 ListView 中显示旁遮普语。 任何建议

像这样创建自定义适配器 -

    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);

并且您必须将字体文件放在名为"fonts"的新文件夹中。

最新更新