1

i have a layout like this:

items.xml:

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_title"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="15dip"
    android:textSize="24sp"/>

i am setting this in Array adapter like this:

here array is String[] array;

adapter.addSection(header, new ArrayAdapter<String>(this, R.layout.items, array));

Now i want to add set color, textsize, custom font progrmatically how to do it?

I know how toset color, textsize and also custom font but how to get the id of this textview?

Goofy
  • 6,098
  • 17
  • 90
  • 156

2 Answers2

0

If you want change color, textsize, font of item in listview then you need to implement ArrayAdapter methods. Create custom Adapter extends ArrayAdapter and it has getView method where you can changed all.

Whenenver ListView shown, ListView ask to give him visible items' view from Adapter and adapter call getView method at this moment you do create item view and return this item view.

Example create use custom adapter ArrayAdapter:

Community
  • 1
  • 1
SBotirov
  • 13,872
  • 7
  • 59
  • 81
0

create style in res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">

        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>

applay it to test view like:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

check this and this artical for more detail.

and You cannot set a view's style programmatically.

add custom font here is example of spinner with custom adapter.

Community
  • 1
  • 1
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177