Yes I use MUMPS
Yes I use MUMPS

Reputation: 226

Android studio swtiches to appcompat when I want to use Holo

I'm doing the intro tutorial from developer.android.com, and would like to see my app using the Holo theme. Unfortunately, Android studio keeps changing the app back to the Theme.AppCompat.Light.DarkActionBar theme instead. The app has two activities. The first one has an EditText and a Button and the second activity just shows a TextView. Before adding the second activity, I was able to apply the Holo theme to the first activity by opening the .xml for the first activity, clicking "Preview" and then choosing the Holo theme from the top of the preview pane. This worked okay. Then I created the second activity, and did the same thing, but now when I run the app, it's not using the Holo theme.

The manifest has:

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

and the style file:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

I've tried changing that line to <style name="android:Theme.Holo">, but that causes the app to crash when I run it.

The tutorial seems to be written using the assumption that Android Studio's default Hello World activities are going to default to Holo, but that doesn't seem to be the case. I don't think that it's because of the versions that I'm trying to support:

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.me.myfirstapp"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}

So my question is twofold. How can I get the app to run using the Holo theme, and how can I get Android Studio to stop switching back to AppCompat every time I create a new activity in the project?

Upvotes: 3

Views: 6270

Answers (3)

jzyamateur
jzyamateur

Reputation: 113

I successfully used holo theme in my project in android studio. Here is how :

  1. In app gradle, Make minSdk, compilesdk and targetsdkversion same(in order to prevent the necessity of fallback behaviour which suggests appcompat library)

  2. Remove entry of appcompat lib in dependencies section in app gradle file.

  3. Now you can simply use android:Theme.Holo.Light in styles.xml of your app.

Upvotes: 0

Yes I use MUMPS
Yes I use MUMPS

Reputation: 226

Following Eugen's advice, which was posted in the comments, I changed my classes so they extend Activity instead of ActionBarActivity.

Upvotes: 1

Willis
Willis

Reputation: 5336

What is the error message that you are getting? My guess would be is that the example Activity in the tutorial possibly extends the ActionBarActivity class. When extending the aforementioned class, you HAVE to use a AppCompat theme (or a descendant), otherwise the application will crash and you will get an error like the following:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myApp/com.example.myApp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

That is the bad news. The good news is that Theme.Holo, which you are trying to use in your example, is aesthetically identical to Theme.AppCompat. So simply change:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to:

<style name="AppTheme" parent="Theme.AppCompat">

and it will look as if you have implemented the Theme.Holo theme.

Upvotes: 0

Related Questions