2012-04-27 62 views
4

有沒有方法可以將樣式應用於佈局xml中特定類型的所有元素,而無需將樣式屬性實際添加到所有元素?將樣式設置爲佈局中的所有TextView元素

我在GridLayout中有很多TextView元素。如果我可以說所有的TextView元素都應該具有「CellFont」樣式而不必將該語句放入每個TextView元素中,那將會很好。下面

解決方案:

添加了GridLayoutCellFont風格style.xml並補充說,風格爲安卓主題,在應用程序清單的活動。

style.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <style name="GridLayoutCellFont"> 
     <item name="android:textSize">22dp</item> 
    </style> 

</resources> 

清單:您可以使用樣式或設定新的主題閱讀更多Styles and Themes教程

+0

你可以分享你的一些代碼? – 2012-04-27 07:38:30

+0

添加了解決方案:) – Mattias 2012-04-27 08:35:54

回答

3

兩個選項。在原始可以定義的風格

0

設置的Android風格或主題

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:theme="@style/GridLayoutCellFont" 
     android:label="@string/app_name" 
     android:name=".TestLayoutsActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
相關問題