我想在我的应用中使用切换按钮。由于其API为11且交换机需要API高于14,我决定使用merge
和include
方法,但我在values-v14/compound_switch.xml
文件中收到此错误:Element merge must be declerd
。这是我的文件,有什么问题?
主要布局:
<include layout="@layout/compound_switch" />
布局/ 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>
值-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>
答案 0 :(得分:0)
将包含切换的布局从文件夹values-v14
移动到名为layout-v14
的文件夹。布局应位于layout
文件夹中。 values文件夹用于颜色,尺寸,属性等。