ListView Android中的自定义字体

ListView Android中的自定义字体,android,listview,android-listview,custom-font,Android,Listview,Android Listview,Custom Font,我在我的应用程序中使用ListView,它有一个自定义适配器,在getView方法中,我使用字体设置自定义字体。但我无法看到这些自定义字体,而且我的应用程序中也没有错误。 下面是listview的java文件 public class Act_Category_ListView extends Activity { ListView act_list; //TextView act_tv; ArrayAdapter<String> listAdapt

我在我的应用程序中使用ListView,它有一个自定义适配器,在getView方法中,我使用字体设置自定义字体。但我无法看到这些自定义字体,而且我的应用程序中也没有错误。 下面是listview的java文件

   public class Act_Category_ListView extends Activity {

    ListView act_list;
    //TextView act_tv;

    ArrayAdapter<String> listAdapter;
    String[] values = new String[]{
        "સેવકનુ ખોટુ", "do", "teen", "4", "5", "6", "6", "7", "8", "9", "10"
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      setContentView(R.layout.act_category_listview);
      act_list = (ListView) findViewById(R.id.act_category_listview);
      //  act_tv = (TextView)findViewById(R.id.tv_act_category);

        // TextView textView = (TextView) rowView.findViewById(R.id.tv_act_category);




        listAdapter = new CustomAdapter_ActCategory(this,R.layout.act_category_listview_textview,values);



        act_list.setAdapter(listAdapter);



        act_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int itemPosition = position;
                String itemValue = (String) act_list.getItemAtPosition(position);
                switch (itemPosition) {
                    case 0:
                        Toast.makeText(getApplicationContext(),
                                "Position :" + itemPosition + "  ListItem : " + itemValue, Toast.LENGTH_LONG)
                                .show();
                        Intent i1 = new Intent(Act_Category_ListView.this, Main_Activity.class);
                        startActivity(i1);
                        break;

                    case 1:
                        Toast.makeText(getApplicationContext(),
                                "Position :" + itemPosition + "  ListItem : " + itemValue, Toast.LENGTH_LONG)
                                .show();
                        Intent i2 = new Intent(Act_Category_ListView.this, Button2_Class.class);
                        startActivity(i2);
                        break;

                }
            }
        });

    }

}
public class Act\u Category\u列表视图扩展活动{
列表视图行为列表;
//TextView act_tv;
阵列适配器;
字符串[]值=新字符串[]{
"સેવકનુ ખોટુ", "“青少年”,“4”,“5”,“6”,“6”,“7”,“8”,“9”,“10”
};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.act\u category\u listview);
act\U list=(ListView)findViewById(R.id.act\U category\U ListView);
//act_tv=(文本视图)findViewById(R.id.tv_act_类别);
//TextView TextView=(TextView)rowView.findViewById(R.id.tv\u act\u category);
listAdapter=new CustomAdapter\u ActCategory(此,R.layout.act\u category\u listview\u textview,值);
act_list.setAdapter(listAdapter);
act_list.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
int itemPosition=位置;
String itemValue=(String)act_list.getItemAtPosition(position);
开关(位置){
案例0:
Toast.makeText(getApplicationContext(),
位置:“+itemPosition+”列表项:“+itemValue,Toast.LENGTH\u LONG)
.show();
意向i1=新意向(Act\u Category\u ListView.this,Main\u Activity.class);
星触觉(i1);
打破
案例1:
Toast.makeText(getApplicationContext(),
位置:“+itemPosition+”列表项:“+itemValue,Toast.LENGTH\u LONG)
.show();
意向i2=新意向(Act\u Category\u ListView.this,Button2\u Class.Class);
星触觉(i2);
打破
}
}
});
}
}
自定义适配器文件

    public class CustomAdapter_ActCategory extends ArrayAdapter<String> {

    private final Context context;
    int layoutResourceId;
    String[] values = new String[]{};
    TextView textView;
    Typeface tf;



    public CustomAdapter_ActCategory(Context context,int layoutResourceId,String[] values) {
        super(context,layoutResourceId,values);
        this.layoutResourceId=layoutResourceId;
        this.context=context;
        this.values=values;
       // tf = Typeface.createFromAsset(context.getAssets(),FONT);
       // act_tv = new TextView(context);
      //  act_tv.findViewById(R.id.tv_act_category);
    //    act_tv.setTypeface(tf); // set typeface here


    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.act_category_listview_textview, parent, false);
        textView = (TextView) rowView.findViewById(R.id.tv_act_category);
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(),"fonts/NotoSansGujarati-Bold.ttf");
        textView.setTypeface(tf);
        textView.setTextColor(Color.DKGRAY);
        return rowView;
    }
}
公共类CustomAdapter\u ActCategory扩展了ArrayAdapter{
私人最终语境;
国际布局资源;
字符串[]值=新字符串[]{};
文本视图文本视图;
字体tf;
公共CustomAdapter\u ActCategory(上下文上下文,int-layoutResourceId,字符串[]值){
超级(上下文、布局资源ID、值);
this.layoutResourceId=layoutResourceId;
this.context=context;
这个。值=值;
//tf=Typeface.createFromAsset(context.getAssets(),字体);
//act_tv=新文本视图(上下文);
//act_tv.findViewById(R.id.tv_act_类别);
//设置字体(tf);//在这里设置字体
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
视图行视图=充气机。充气(R.layout.act\u category\u listview\u textview,父级,false);
textView=(textView)rowView.findViewById(R.id.tv\u act\u category);
Typeface tf=Typeface.createFromAsset(getContext().getAssets(),“字体/非古吉拉特邦粗体.ttf”);
textView.setTypeface(tf);
textView.setTextColor(Color.DKGRAY);
返回行视图;
}
}
ListView.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/act_category_listview"
    >

</ListView>

ListView的TextView.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_act_category"
android:layout_gravity="center_horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="@color/dark_gray"
xmlns:android="http://schemas.android.com/apk/res/android" />

字体可能写得不好,请尝试对其重新编码。试用此免费在线工具


上载字体文件并将其转换“即使将其转换为相同格式,文件仍将被重新编码”

是的,我有字体文件夹,是的,textview@saeed中没有显示文本您不想在textview中显示文本吗?您没有在文本视图中设置文本字体可能写得不好