jsp
jsp

Reputation: 2636

set the textsize of a listview

I have a custom listview and have defined a style for it. I am not able to change the textsize of the items on listview. I am trying to change it through layout so that it can dynamically change depending on device.

styles.xml

<style parent="@android:attr/listViewStyle" name="ListStyle">
    <item name="android:background">@android:color/white</item>
    <item name="android:divider">@drawable/divider</item>
    <item name="android:textSize">26dp</item>
    <item name="android:textStyle">bold</item>
</style>

xml layout

<TvList style="ListStyle"
     android:id="@+id/mainview" 
    android:layout_height="300dp"
    android:layout_width="wrap_content" />

I know that i can use setTextSize in my code for changing the font size . But i want to change it applying styles. Any suggestions on how to go about changing it?

Thanks

Upvotes: 0

Views: 2689

Answers (2)

Ashterothi
Ashterothi

Reputation: 3282

The size of the text within the List View is defined by the ListView's adapter's item resource. If you create a custom view for the list view item and define a TextView, you can change the size of the font within that text view, which will define the size of the text in each item within the List.

Upvotes: 2

Shawn Lauzon
Shawn Lauzon

Reputation: 6282

I would say the best way is to define resource files that you want and then override them in different configurations. For example, create a values/dimen.xml file and define:

 <dimen name="text_size_medium">18sp</dimen>

and then create another file values-large/dimen.xml which defines

 <dimen name="text_size_medium">22sp</dimen>

Then you just say in your styles.xml:

 <item name="android:textSize">@dimen/text_size_medium</item>

Upvotes: 1

Related Questions