PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

How can I automatically apply the style of the parent?

I have a layout that contains a custom layout. I would like to pass the style from one element to another. I have a class which inflates the layout, which I can post if required. This element of design is added by 2 different layouts, with different sizes depending on what is required.

Child layout

<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal">
    <TableRow android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_width="fill_parent" android:id="@+id/tableRow1">
        <Button android:text="1" android:id="@+id/nb1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
        <Button android:text="2" android:id="@+id/nb2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
        <Button android:text="3" android:id="@+id/nb3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40sp" android:layout_margin="1dip" android:minWidth="70dip"></Button>
    </TableRow>
</TableLayout>

And here's the parent layout

Parent Layout

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <pearsonartphoto.AJEG.number_viewer android:id="@+id/numberviewer" style="@style/bigViewer" android:layout_alignParentRight="true" android:layout_alignParentBottom="true">
    </pearsonartphoto.AJEG.number_viewer>
</RelativeLayout>

What I would like to do is to pass in a style, and have the style be repeated through all of the children, or at least the textView elements. What do I need to do to make this happen?

Upvotes: 2

Views: 3090

Answers (1)

Lukap
Lukap

Reputation: 31963

As far as I know there is no way in android to inherit the style of parent to the children views, not by just nesting them !

the thing that you could to is to apply a style to the parent let say styleA, and than apply a style to the children elements let say styleB

and the inheritance could be done in the styles, I mean styleB can inherit properties from styleA and also override some of his parent values

fill_parent wrap_content #00FF00 monospace

fill_parent wrap_content #00FF00 monospace

the bad news is that you must put style in every children element :-(

I think this is the only way to give a style to some element, if you want to give a style to group of elements than you must define theme and apply it to the activity or to the application this is done usually in code but it could be done pro programmaticlly also.

Upvotes: 3

Related Questions