gsgx
gsgx

Reputation: 12239

Forcing app using ActionBarSherlock to use Theme and not Theme.Holo

I have an app that was originally styled for Android 2.3. Now I'm adding an ActionBar with ActionBarSherlock, and everything is fine, except on my Nexus 7 running 4.2, it's now using the Holo theme for buttons and for EditTexts. Before my theme was inheriting from Theme.Light and now it's inheriting from Theme.Sherlock. I want it to use the old theme even on newer devices. I suspected that this was caused by the following line in the values-v14 folder:

<style name="Sherlock.__Theme" parent="android:Theme.Holo">

So I tried removing that folder and the v11 folder just to see if it would fix the problem, but then the ActionBar went away completely.

Then I tried overriding the style for the EditText like this:

<style name="AppTheme" parent="Theme.Sherlock">
    <item name="@android:attr/editTextStyle">@android:style/Widget.EditText</item>
</style>

That should have made the widget not use the Widget.Holo theme and use the regular theme, but it didn't work.

How do I make Android 4.0+ devices use the original theme instead of the Holo theme while using ABS?

Below I've posted some code for a sample application using ABS that is currently showing a Holo themed EditText but should be showing a regular EditText:

MainActivity.java:

import android.os.Bundle;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;

public class MainActivity extends SherlockActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />
    <EditText 
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</RelativeLayout>

styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme" parent="Theme.Sherlock">
        <item name="@android:attr/editTextStyle">@android:style/Widget.EditText</item>
    </style>

</resources>

Also, the theme in the manifest is AppTheme and ABS is added as a library project.

Upvotes: 3

Views: 2140

Answers (2)

gsgx
gsgx

Reputation: 12239

The reason my fix wasn't working was because the background attribute of Widget.EditText was using the ?attr syntax, which means it was using the background of the current theme, which was Holo. So I essentially looked at the Android source and changed the two attributes that used this syntax back to what I believed should be pre-Holo theme styles (i.e. setting the background to white).

Upvotes: 0

antew
antew

Reputation: 7478

This wouldn't be caused by ActionBarSherlock, the EditText and Button themes are defined by the platform you are running, in this case 4.2. EditTexts and Buttons may also look different based on the UI skin, (TouchWiz, Sense, MotoBlur, etc).

I would recommend keeping the Holo theme on devices that support it because users will be familiar with it and having the 2.x theme on 3.x+ will look out of place.

Also, one of the Sherlock themes is required in order to use ActionBarSherlock according to the docs:

In order for the custom action bar implementation to function your application must use Theme.Sherlock, Theme.Sherlock.Light, or Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one of the aforementioned as its parent.

If you really want the 2.x look for Buttons and other Widgets I believe you would need to copy all of the styles/drawables from 2.x and then override them in one of the Sherlock derived themes. You could take a look at what Chris Versieux has done with HoloEverywhere and try to do the reverse making everything look like 2.x, I would strongly recommend against it though.

Upvotes: 2

Related Questions