创建样式-v21.xml [英] Creating styles-v21.xml

查看:75
本文介绍了创建样式-v21.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Studio中,我导入了一个不包含styles.xml (v21)的项目. 因此,我在values目录中创建了一个styles-v21.xml文件. styles.xmlstyles-v21.xml现在都在values目录中.

In Android Studio, I imported a project which did not include styles.xml (v21). So I created a styles-v21.xml file in the values directory. Both styles.xml and styles-v21.xml are in the values directory now.

styles.xml

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="AppTheme.Base">
        <!-- Customize your theme here. -->
    </style>

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light">

    </style>

</resources>

styles-v21.xml

styles-v21.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">

    </style>

</resources>

构建项目时出现构建错误:

When I build the project I get a build error:

错误:错误:资源重复:C:\ xxx \ main \ res \ values \ styles-v21.xml:style/AppTheme,C:\ xxx \ main \ res \ values \ styles.xml:style/AppTheme

Error:Error: Duplicate resources: C:\xxx\main\res\values\styles-v21.xml:style/AppTheme, C:\xxx\main\res\values\styles.xml:style/AppTheme

错误是两个资源文件具有相同的style名称:AppTheme. 但是在我见过的其他项目和教程中,这些styles具有相同的名称.一个用于具有版本21兼容性的Android,另一种用于不具有版本21的Android.

The error is that both resource files have the same style name: AppTheme. But in other projects and tutorials I've seen, these styles have the same name. One is for Android with version 21 compatibility and the other is for Android without the compatibility.

我想我想知道是否应该简单地更改名称,或者这些文件应该具有相同的名称-这意味着手头有更大的问题.我应该如何进行?

I guess I want to know if I should simply change the name or if these files are supposed to have the same name - which means there is a bigger problem at hand. How should I proceed?

推荐答案

右键单击res文件夹,选择新建-> Android资源文件,设置相同的名称对于新文件样式",在可用的限定词中:选择最后一个项目"版本",最后设置"平台API级别" 21.

Right click on res folder, choose New --> Android resource file, set the same name for the new file "styles", in Available qualifiers: choose the last item "Version" and finally set "Platform API level" 21.

这篇关于创建样式-v21.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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