Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop using AppCompat in Android Studio?

I'm new to Android development and I'm trying to follow Android development guide in Android Studio, specifically trying to set up an action bar.

My minSdkVersion is 15, stated in build:gradle(Module:app) so I would think I wouldn't need to use any App Compatibility Support but my theme, as it says in styles.xml is <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> and I can't change it to any Holo whitout crashing my app anytime I run it.

Besides, using this one I can't use android:showAsAction(it just doesnt work) and instead need to use app:showAsAction and all the Android Support library.

Thanks in advance.

like image 598
Joaquim Ferrer Avatar asked Jul 10 '15 10:07

Joaquim Ferrer


People also ask

What is AppCompat in Android Studio?

When new versions of android are published, Google will have to support the older versions of android. So AppCompat is a set of support libraries which can be used to make the apps developed with newer versions work with older versions.

How do I fix AppCompat error v7?

How do I fix AppCompat error v7? "You must have the latest versions of SDK Tools / Build Tools / Platform Tools." This trick resolved my problem. I have all updated Tools except "Build Tools". So I just update the "Build Tools", restarted eclipse then clean "appcompat" project and found my problem is solved.

Why do we extend AppCompatActivity?

AppCompatActivity enables many of the backwards compatibility features in a transparent manner. For example, implements Material Design views and features not available in 4.0. So, it's still a good practice to use it.

Should I use AppCompatActivity?

For a minimum API level of 15,the use of AppCompatActivity is recommended. Activity is the base class of all other activities, which i assume you mean as Normal Activity.


1 Answers

CommonsWare provided the correct steps but I still battled as there wasn't enough details for me to know exactly what to do (being new to Android Studio and Android development).

I found a blog post that explains the details here and it worked for me: https://mobiarch.wordpress.com/2015/04/17/removing-support-library-in-android-studio

Here is what it says (I have added some additional help):

Open build.gradle from your project. Locate the dependencies section.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

Remove the line for the compatibility library. After that the section should look like this.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Save and close.

By default the app uses a theme that is available from the support library. This is not available from the core API. So we need to fix that. Open res/values/styles.xml. The style tag will look something like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

Change the parent to a theme that is available from the core SDK. For example:

<style name="AppTheme" parent="android:style/Theme.Holo.Light">
    <!-- Customize your theme here. -->
</style>

Rename properties in the activity xml files such as app:showAsAction to android:showAsAction.

Extent your activity classes from Activity instead of ActionBarActivity and AppCompatActivity. You'll have to press Alt+Enter on Activity once you have made the changes to add import android.app.Activity at the top of the file. See the example below:

Change:

import android.support.v7.app.ActionBarActivity;

public class DisplayMessageActivity extends ActionBarActivity {
    .
    .
    .
}

to:

import android.app.Activity;

public class DisplayMessageActivity extends Activity {
    .
    .
    .
}

And the same for any other activities that extends ActionBarActivity and AppCompatActivity

Finally, perform a Build | Clean Project and a Build | Rebuild Project to sort out the current build errors.

like image 154
Donatello Avatar answered Oct 19 '22 14:10

Donatello