小编Ste*_*ven的帖子

android更改listview字体和颜色

我已经找到了许多不同的方法来实现这一点,但我不确定什么是最适合我的方案.

这是我的listview的Java代码:

ListView lv;
lv = (ListView) findViewById(R.id.favList);
Run Code Online (Sandbox Code Playgroud)

这是列表的xml代码:

<ListView
        android:id="@+id/favList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="40dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@android:color/transparent" >
    </ListView>
Run Code Online (Sandbox Code Playgroud)

对于文本视图,我会添加:

final Typeface fontList = Typeface.createFromAsset(assets, "optima-extra-black.ttf");
lv.setTypeface(fontList);
Run Code Online (Sandbox Code Playgroud)

但这对listviews不起作用.在这种情况下如何更改字体?

我几乎就在那里......我需要访问我的资产,但我无法从我的自定义适配器中访问.我试过用final AssetManager assets = this.getAssets();但不会让我更进一步..

如何解决这个问题?

    class Myadapter extends BaseAdapter {

    LayoutInflater lif;
    ImageView sideArrow;
    TextView tv;


    public Myadapter(Context ctx) {
        lif = (LayoutInflater) ctx
                .getSystemService(LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {

        return favarets.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long …
Run Code Online (Sandbox Code Playgroud)

fonts android listview android-listview

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

android-listview ×1

fonts ×1

listview ×1