Android-合并和包含



我想在我的应用程序中使用切换按钮。由于它的API是11,交换机需要高于14的API,我决定使用mergeinclude方法,但我在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文件夹中。值文件夹用于颜色、尺寸、属性等。

最新更新