Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to use holo theme in Android not working

I've been trying to set a holo theme in Android, but I haven't been able to get it to recognize it. Any ideas?

Posted is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:theme="@android:style/Theme.Holo">
        <activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

It gives me the red line under @android:style/Theme.Holo even if I change the minSdkVersion to 11. Any ideas?

Update:

I changed the line <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/> to <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/> and I am still getting the same error.

Update 2:

This ended up being that my target api was specified correctly in the manifest, but not in project properties. Weird, but now as is well.

like image 486
EGHDK Avatar asked Jun 21 '12 01:06

EGHDK


People also ask

How do I apply a theme to my android?

To change default themes go to File and click on Settings. A new Settings dialog will appear, like this. Under the Appearance & Behaviour -> Appearance, you will find Theme. Choose the right theme from the drop-down and click on Apply and then Ok.

What is theming in Android?

A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view. When you apply a theme, every view in the app or activity applies each of the theme's attributes that it supports.


2 Answers

Eclipse is giving you an error because SDK versions 7-10 won't know what Theme.Holo is. You need to provide separate styles for both platforms to ensure that the correct style will be found at runtime.

  1. In your res/values/styles.xml file, create the following style:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.MyTheme" parent="@android:style/Theme.Black" />
    </resources>
    
  2. In your res/values-v11/styles.xml file, create the following style:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.MyTheme" parent="@android:style/Theme.Holo" />
    </resources>       
    
  3. In your AndroidManifest.xml file, use the following line for your application's theme:

    android:theme="@style/Theme.MyTheme"
    
like image 185
Alex Lockwood Avatar answered Oct 31 '22 18:10

Alex Lockwood


you are trying to use the Holo theme for API Low than Android 4.0 that's why you get the red Line you can:

  1. Use the HoloEverywhere project
  2. Pick the necessary resources for Holo Theme you most want from the ICS source and create your own custom theme/styles https://github.com/android/platform_frameworks_base/tree/master/core/res
  3. You ca also try to make use a custom theme for Android Api 7 to 10 and the holo theme for Api 11 and higher, see @Alex Lockwood's answer.
like image 39
K_Anas Avatar answered Oct 31 '22 19:10

K_Anas