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

查看:43
本文介绍了如何在 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) 中说明,所以我认为我不需要使用任何应用程序兼容性支持但我的主题,正如它在 styles.xml 中所说的是 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">我无法将其更改为任何 Holo whitout 使我的应用程序在运行时崩溃.

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:showAsAction)重命名为 android:showAsAction.

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

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

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 Project 和一个 Build |重新构建项目以整理当前构建错误.

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

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

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