如何停止在Android Studio中使用AppCompat? [英] How to stop using AppCompat in Android Studio?

查看:114
本文介绍了如何停止在Android Studio中使用AppCompat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发的新手,我正在尝试遵循Android Studio中的Android开发指南,尤其是尝试设置操作栏.

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.

我的minSdkVersion15,在build:gradle(Module:app)中表示,所以我认为我不需要使用任何App兼容性支持,但我的主题(如styles.xml中所述)是<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">我无法将其更改为任何在我运行应用时使我的应用崩溃的Holo版本.

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.

此外,使用此我不能使用android:showAsAction(它行不通),而需要使用app:showAsAction和所有Android支持库.

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.

谢谢.

推荐答案

CommonsWare提供了正确的步骤,但我仍在努力,因为没有足够的详细信息让我确切地知道要做什么(Android Studio和Android开发的新手) ).

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).

我找到了一篇博客文章,其中解释了详细信息,并且对我有用: https://mobiarch.wordpress.com/2015/04/17/removing-support-library-in-android-studio

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):

从您的项目中打开build.gradle.找到依赖项部分.

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'])
}

保存并关闭.

默认情况下,应用程序使用支持库中提供的主题.核心API无法提供此功能.因此,我们需要解决该问题.打开res/values/styles.xml.样式标签如下所示:

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>

将父项更改为可从核心SDK获得的主题.例如:

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>

将活动xml文件中的属性重命名,例如从app:showAsActionandroid:showAsAction.

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

Activity而不是ActionBarActivityAppCompatActivity扩展您的活动类.进行更改后,必须在Activity上按Alt + Enter,以在文件顶部添加import android.app.Activity.请参见下面的示例:

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:

更改:

import android.support.v7.app.ActionBarActivity;

public class DisplayMessageActivity extends ActionBarActivity {
    .
    .
    .
}

收件人:

import android.app.Activity;

public class DisplayMessageActivity extends Activity {
    .
    .
    .
}

对于扩展ActionBarActivityAppCompatActivity

最后,执行Build | Clean ProjectBuild | Rebuild Project来找出当前的构建错误.

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

这篇关于如何停止在Android Studio中使用AppCompat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆