android zmienić czcionkę listview i kolor
Znalazłem mnóstwo różnych sposobów osiągnięcia tego, ale nie jestem pewien, co jest najlepsze dla mojego scenariusza.
To jest mój kod Java dla widoku listy:
ListView lv;
lv = (ListView) findViewById(R.id.favList);
To jest kod XML dla listy:
<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>
Do widoku tekstu dodałbym:
final Typeface fontList = Typeface.createFromAsset(assets, "optima-extra-black.ttf");
lv.setTypeface(fontList);
Ale to nie działa w przypadku listviews. Jak w tym przypadku zmienić czcionkę?
Oke jestem prawie tam ... Muszę uzyskać dostęp do moich zasobów, ale nie mogę z poziomu mojego niestandardowego adaptera. Próbowałem użyćfinal AssetManager assets = this.getAssets();
ale to nie pozwoli mi dalej ...
Jak sobie z tym poradzić?
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 getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = lif.inflate(R.layout.inflate, null);
sideArrow = (ImageView) vi.findViewById(R.id.imageViewsidemark);
tv = (TextView) vi.findViewById(R.id.textFav);
tv.setText(favarets.get(position));
final AssetManager assets = this.getAssets();
final Typeface tvFont = Typeface.createFromAsset(assets, "OPTIMA.TTF");
tv.setTypeface(tvFont);
tv.setTextColor(Color.BLACK);
return vi;