【问题标题】:SwitchCompat not showing on deviceSwitchCompat 未在设备上显示
【发布时间】:2016-08-06 14:38:09
【问题描述】:

我正在尝试使用 SwitchCompat,它显示在 Android Studio 的设计视图中,但在我的 Galaxy S4(运行 5.0.1)上,它没有显示。以下是相关代码:

activity.xml

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

build.gradle

dependencies {
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}

【问题讨论】:

    标签: android xml material-design android-appcompat


    【解决方案1】:

    这就是我最终得到它的方式:

    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 资源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 2018-05-27
      • 2021-09-18
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多