2015-05-26 66 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