How to stop using AppCompat in Android Studio?

后端 未结 2 1935
旧时难觅i
旧时难觅i 2020-12-10 06:10

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.

相关标签:
2条回答
  • 2020-12-10 06:26

    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.

    0 讨论(0)
  • 2020-12-10 06:35

    Step #1: Change your theme away from Theme.AppCompat

    Step #2: Remove appcompat-v7 from your list of dependencies in your app module's build.gradle file

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

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

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

    Here is a sample project that uses the native action bar.

    0 讨论(0)
提交回复
热议问题