Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 458
Torsten Römer Avatar asked Jul 22 '11 20:07

Torsten Römer


People also ask

How to include layout in another layout android studio?

To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.

How to use include tag in android?

Include Tag:The <include/> tag helps us to include the xml content's in our xml file. This is a nice way to share layout parts between different layout's. Suppose we need to show the custom title in many layouts, for that we simply create a custom layout for title bar and then reuse the layout by using <include/> tag.


1 Answers

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.

like image 52
antonyt Avatar answered Oct 23 '22 05:10

antonyt