2015-05-26 70 views
1

我有兩組視圖應該使用不同的樣式,只需將它們稱爲leftStyles和rightStyles。有沒有像風格組?

這兩組視圖都有相同的layout.xml,我想通過程序改變容器的「styleGroup」來改變它所有的兒童風格,就像一個主題。 它是否存在可應用於佈局的「查看組級別」主題?

這兩組在同一頁面中,所以我不能將它們與主題區分開來。

有什麼方法可以在ViewGroup中設置一組樣式,所以樣式可以由它的孩子使用?

回答

1

我希望它能幫助you.This是風格,你可以聲明組的風格,兒童風格,款式單一......就這樣

<style name="Widget.Group" parent="@android:style/Widget"> 
     <item name="android:layout_width">match_parent</item> 
     <item name="android:layout_height">46dp</item> 
     <item name="android:layout_marginLeft">10dp</item> 
     <item name="android:layout_marginRight">10dp</item> 
     <item name="android:layout_marginTop">-1dp</item> <!-- Ensures we don't get a 2 dp top stroke --> 
     <item name="android:padding">4dp</item> 
     <!--<item name="android:background">@drawable/bg_input_group</item>--> 
    </style> 

    <style name="Widget.Group.Top"> 
     <item name="android:layout_marginTop">10dp</item> 
     <!--<item name="android:background">@drawable/bg_input_group_top</item>--> 
    </style> 

    <style name="Widget.Group.Bottom"> 

     <item name="android:layout_marginTop">20dp</item> 
     <!--<item name="android:background">@drawable/bg_input_group_bottom</item>--> 
    </style> 

    <style name="Widget.Group.Single" parent="Widget.Group.Top"> 
     <!--<item name="android:background">@drawable/bg_input_group_single</item>--> 
    </style> 

和佈局文件,你的CAD使用這種風格類似這樣的方式

<?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="#eee"> 

    <!-- Input Group --> 
    <EditText style="@style/Widget.Group.Top" /> 
    <EditText style="@style/Widget.Group" /> 
    <EditText style="@style/Widget.Group.Bottom" /> 

    <!-- Single item --> 
    <EditText style="@style/Widget.Group.Single" /> 

</LinearLayout> 

更多細節click

+0

謝謝,但這不是我想要的。我有一個用於我的widget組件的layout.xml,我想像程序化地改變容器的「styleGroup」來改變它的所有孩子的風格,就像一個主題一樣(我不確定這是否可以實現)在你的演示代碼中,我們應該改變每個孩子的風格。 – Malloc