创建样式-v21.xml [英] Creating styles-v21.xml
问题描述
在 Android Studio 中,我导入了一个不包含 styles.xml (v21)
的项目.所以我在 values
目录中创建了一个 styles-v21.xml
文件.styles.xml
和 styles-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
<?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
具有相同的名称.一个是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屋!