我想在我的应用程序中使用切换按钮。由于它的API是11,交换机需要高于14的API,我决定使用merge
和include
方法,但我在values-v14/compound_switch.xml
文件Element merge must be declerd
中得到了这个错误。这是我的文件,出了什么问题?
主布局:
<include layout="@layout/compound_switch" />
layout/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView20"
android:layout_toLeftOf="@+id/textView20"
android:layout_toStartOf="@+id/textView20"
android:layout_marginRight="5dp"
android:checked="false" />
</merge>
values-v14/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:id="@+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView20"
android:layout_toLeftOf="@+id/textView20"
android:layout_toStartOf="@+id/textView20"
android:layout_marginRight="5dp" />
</merge>
将具有开关的布局从文件夹values-v14
移动到名为layout-v14
的文件夹。布局应该在layout
文件夹中。值文件夹用于颜色、尺寸、属性等。