Torsten Römer
Torsten Römer

Reputation: 3926

Possible to override/apply style in layout included with <include> tag?

I am including an (internal) layout in my own layout like this:

<include android:id="@+id/twolinelistitem" 
    layout="@android:layout/simple_list_item_2"
    style="@style/TwoLineListItem"/>

but the style is not applied. This blog post doesn't mention that this should work so I'm okay if it doesn't.

So the only way to set i.e. the background is programmatically?

Here is a somewhat related android Issue

Upvotes: 25

Views: 5517

Answers (2)

D. Sergeev
D. Sergeev

Reputation: 2355

It is possible if you override layout width and height

<include android:id="@+id/twolinelistitem" 
    layout="@android:layout/simple_list_item_2"
    style="@style/TwoLineListItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Upvotes: 0

antonyt
antonyt

Reputation: 21883

Unfortunately, this does not seem to be possible. Only the layout parameters (if both height and width are set...), id, and visibility are passed from the include tag to the actual layout. Setting a style on the include tag does not seem to have an effect.

You can see the source code for parsing an include here.

Upvotes: 25

Related Questions