2012-02-17 103 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