Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a different theme to a Layout

I've set a default theme for the whole app. It's defined in styles.xml as follows:

    <style name="DefaultTheme" parent="@android:style/Theme.Holo.Light">         <!-- Customization here -->     </style> 

I've also defined a dark theme:

    <style name="DarkTheme" parent="@android:style/Theme.Holo">         <!-- Customization here -->     </style> 

In the manifest it is declared the light theme as the main theme for the app:

    <application     ...     android:theme="@style/DefaultTheme" > 

Now this is working fine, but in an activity, I need to set a different theme for a single Layout. Something like this:

    +--------------------------------------------------+     |         Parent Linear layout (default theme)     |     |                                                  |     | +------------------------------------+ +-------+ |     | |                                    | |       | |     | |     Left linear layout             | |       | |     | |     (default theme)                | |       | |     | |                                    | |       | |     | |                                    | |       | |     | |                                    | |    ·<----------- Right Linear Layout     | |                                    | |       | |        (Need it in dark theme)     | |                                    | |       | |     | |                                    | |       | |     | +------------------------------------+ +-------+ |     +--------------------------------------------------+ 

In the layout xml file I'm trying to set a theme for the rightmost child LinearLayout:

    <LinearLayout     style="@style/DarkTheme">     ... 

I'd expect this to work just fine, and to apply the dark theme to the right layout only (and its child views), but it is not working. I've tried replacing the @style with a built-in @android:style to no avail. I've tested this in the layout editor and on real device/simulator.

Is it possible to apply a custom theme or style to a single layout?

like image 839
Mister Smith Avatar asked Aug 29 '13 09:08

Mister Smith


People also ask

How to put different themes in PowerPoint?

Select the slide that you want to apply a different theme to. Hold down CONTROL and then, on the Themes tab, under Themes, click the slide that you want to apply the theme to, and click Apply to Selected Slides.

Can I use more than one template in PowerPoint?

Microsoft PowerPoint allows you to combine two or more presentations with different theme templates. PowerPoint includes a Keep Source Formatting option that retains the template format for each slide.

What is theme and layout?

A layout includes the HTML for a basic webpage structure and allows you to provide your own content. This gives you more freedom over the appearance of your design. A theme includes three pages (index. html, about-us.

How do I set my theme?

Settings. Under Display Options, tap Theme. Select the theme for this device: Light—White background with dark text.


1 Answers

This is now possible by using the android:theme property on the view and setting it to any theme you like. Note that the child views will inherit the theme of their parent.

like image 113
Miro Markaravanes Avatar answered Sep 19 '22 20:09

Miro Markaravanes