oursgris
oursgris

Reputation: 2882

Apply a custom theme on a LinearLayout

I'd like to apply a whole custom theme on a LinearLayout.

I'm using the SlidingMenu of https://github.com/jfeinstein10/SlidingMenu and I'd like to apply the Hol theme while the rest of the application would be in Holo.Light.

My actual styles.xml contains :

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

<style name="SlidingTheme" parent="android:Theme.Holo">
</style>

My code to attach the sliding menu is :

    // configure the SlidingMenu
    SlidingMenu menu = new SlidingMenu(activity);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setBehindWidth(200);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(activity, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.slidingmenu);

How can I apply my theme to my LinearLayout ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  style="@style/SlidingTheme" >

<Button
    android:id="@+id/imageButton1"
    android:layout_width="187dp"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_action_group"
    android:drawableStart="@drawable/ic_action_group"
    android:text="@string/customer"
    style="@style/SlidingTheme" />

</LinearLayout>

My goal is to apply the style (holo dark) to only the SlidingMenu or my linearlayout (and its content). I have the feeling I can't apply that on my LinearLayout.

Upvotes: 0

Views: 3910

Answers (1)

Phant&#244;maxx
Phant&#244;maxx

Reputation: 38098

You can apply themes to Activities or Fragments, or even to the whole application.
This is done inside the AndroidManifest.xml file.
So, do something like this in your manifest:

<!-- Apply the common theme for the whole application -->
<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.your_theme"
    android:installLocation="auto"
    >
    <!-- ... -->
    <!-- This activity has its own theme -->
    <activity
        android:name="com.your_company.your_app.your_other_activity"
        android:theme="@style/Theme.your_other_theme"
    />

Upvotes: 1

Related Questions