繁体   English   中英

为什么 SwitchCompat 在 Android Studio 上不起作用?

[英]Why is SwitchCompat not working on Android Studio?

为什么 SwitchCompat 不工作并且有这个灰色的矩形形状? 我想我已经尝试了几乎所有东西,但它仍然不想工作。

Gradle 文件:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ustawienia">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"/>

<include layout="@layout/content_ustawienia" />

    <android.support.v7.widget.SwitchCompat
        android:id="@+id/switch_animacja"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"/>
    
</androidx.coordinatorlayout.widget.CoordinatorLayout>

代替

android.support.v7.widget.SwitchCompat

利用

androidx.appcompat.widget.SwitchCompat

除此之外,您还将support libraryAndroidX library混合在一起。 尝试删除support library ,因为它们已被弃用。

如果您没有将项目完全迁移到AndroidX然后通过从Android Studio菜单栏中选择Refactor > Migrate to AndroidX来迁移它,然后按Do Refactor

查看官方文档以获取更多详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM