Android SwitchCompat未在设备上显示
我正在尝试使用SwitchCompat,它显示在Android Studio的设计视图中,但在我的Galaxy S4(运行5.0.1)上,它没有显示。以下是相关代码: activity.xmlAndroid SwitchCompat未在设备上显示,android,xml,material-design,android-appcompat,Android,Xml,Material Design,Android Appcompat,我正在尝试使用SwitchCompat,它显示在Android Studio的设计视图中,但在我的Galaxy S4(运行5.0.1)上,它没有显示。以下是相关代码: activity.xml <RelativeLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_ma
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/monitoring_text"
android:id="@+id/textView8"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/monitoring_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
app:showText="false"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView8"
android:layout_centerHorizontal="true" />
</RelativeLayout>
这就是我最终让它工作的方式: 1-下载Android支持存储库 2-添加xmlns:app=”http://schemas.android.com/apk/res-auto“添加到您的活动XML 3-在您的活动中使用AppCompat版本的小部件,例如导入android.support.v7.widget.SwitchCompat 4-确保将styles.xml和AndroidManifest.xml中的主题设置为AppCompat主题之一 5-如果出现错误,请尝试使缓存无效并重新启动,以便重置R资源
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}