Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

android - Creating styles-v21.xml

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

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

Error:Error: Duplicate resources: C:xxxmain esvaluesstyles-v21.xml:style/AppTheme, C:xxxmain esvaluesstyles.xml:style/AppTheme

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...