2012-02-17 110 views
0

我有一个列表视图:设置字体样式列表视图

<ListView 
     android:id="@+id/my_list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     style="@style/listFontStyle" 
/> 

正如你看到的上面,我有一个样式设置到列表中。

listFontStyleres/values/styles.xml下定义:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="listFontStyle"> 
     <item name="android:textSize">28sp</item> 
    </style> 
</resources> 

我居住在Java代码中的列表内容。基本上我将一个字符串列表设置为一个适配器。然后将适配器设置为列表视图。 (在Java代码中没有问题)

我的问题是我设置为列表视图的样式不起作用,字体大小不变,为什么?

** * *UPDATE* ** *

好吧,可能是更好的更新我的问题:我怎样才能设置样式到list view其中没有项目布局文件,但只填充列表内容的Java代码与simpleAdapter和字符串列表?

+0

我猜你应该加上'风格=“@风格/ listFontStyle“' 在你的列表项目上,而不是直接在你的列表上 – 2012-02-17 09:09:12

+0

正如我所说的,我使用Java代码来填充列表,使用简单的适配器和一个字符串列表,我如何将样式添加到我的项目?在我的情况下根本没有项目布局文件。 – 2012-02-17 09:11:39

+0

然后你需要有一个包含textview的custom_listitem.xml文件,并且在该文本视图中,你必须在填充listview时指定style.and,而不是使用默认的listitem来给这个xml文件名称。 – Hiral 2012-02-17 10:25:26

回答

0

好吧,这是你如何能做到这样的例子:

SimpleAdapter mSchedule = new SimpleAdapter(this.getBaseContext(), listItem, R.layout.list_categories_item, new String[] { "categoryName" }, new int[] { R.id.categoryName }); 

这里是list_categories_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@drawable/bg_list_category_item"> 

<TableLayout 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <TableRow> 
     <TextView android:id="@+id/categoryName" 
      android:layout_width="70dip" android:layout_height="wrap_content" 
      android:layout_weight="1" android:text="test" android:paddingLeft="10dp" 
      android:paddingRight="10dp" android:paddingBottom="5dp" 
      android:paddingTop="5dp" android:textStyle="bold" android:textSize="25dp" android:textColor="@color/black" android:shadowColor="#FFFFFFFF"/> 
    </TableRow> 
</TableLayout> 

</LinearLayout> 
+1

****更新**** 我不认为这是可能的。 你应该真的考虑使用项目布局xml,它没有太多的工作,将是一个适当的解决方案。 希望它有帮助 – 2012-02-17 13:35:44