How to stop using AppCompat in Android Studio?

I am new to Android development, and I try to follow the Android development guide in Android Studio, in particular , trying to customize the action bar .

My minSdkVersion 15 is specified in build:gradle (Module: app), so I think I will not need to use application compatibility support, but my theme, as stated in styles.xml , is <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> and I can't change it for any case when I start it anytime when I start it .

Also, using this one , I cannot use android:showAsAction (it just does not work) and instead I need to use app:showAsAction and the entire Android support library.

Thanks in advance.

+7
source share
2 answers

CommonsWare provided the right steps, but I still fought because I lacked the details so that I knew exactly what to do (being new to Android Studio and Android).

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's what he says (I added extra help):

Open build.gradle from your project. Find the dependency section.

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

Delete 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 application uses a theme available from the support library. This cannot be obtained from the main API. Therefore, we need to fix it. 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 accessible from the main SDK. For instance:

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

Rename properties in activity xml files, such as app:showAsAction - android:showAsAction .

Extract activity classes from Activity instead of ActionBarActivity and AppCompatActivity . You will need to press Alt + Enter on the Activity after making the changes to add import android.app.Activity at the top of the file. See the example below:

Edit:

 import android.support.v7.app.ActionBarActivity; public class DisplayMessageActivity extends ActionBarActivity { . . . } 

in

 import android.app.Activity; public class DisplayMessageActivity extends Activity { . . . } 

And the same for any other actions that extend ActionBarActivity and AppCompatActivity

Finally, run the Build | Clean Project Build | Clean Project and Build | Rebuild Project Build | Rebuild Project to sort current build errors.

+8
source

Step # 1: Change Theme from Theme.AppCompat

Step # 2: Remove appcompat-v7 from the dependencies list in the app build.gradle file <

Step # 3: Change all actions to not inherit from AppCompatActivity or ActionBarActivity , but instead inherit something else, like Activity

Step # 4: Change all menu resources by replacing app: with android:

Step # 5: Perform a clean rebuild (Build> Clean Project) and fix any lingering compilation errors caused by the above four steps.

Here is an example project that uses its own action bar.

+6
source

All Articles