无法在android studio中解析符号'coordinatorlayout'

uidvcgyl  于 2023-01-31  发布在  Android
关注(0)|答案(2)|浏览(223)

我正在创建一个Android应用程序并使用坐标布局,但我遇到了这个错误。已在build.gradle文件和activity_main. xml文件中添加了坐标布局。其他类工作正常,只是在这一行代码中有问题。是否有其他方法可以将坐标布局替换为任何其他布局设计。
这是我的MainActivity.java文件,已经导入了设计布局。在activity_main.xml文件中也是如此。
MainActivity.java

import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;

public class MainActivity extends AppCompatActivity {
    ...
    ...
    @BindView(R.id.image_preview)
    ImageView imagePreview;

    @BindView(R.id.tabs)
    TabLayout tabLayout;

    @BindView(R.id.viewpager)
    ViewPager viewPager;

    @BindView(R.id.coordinator_layout)  //here I'm getting error 'cannot resolve symbol 'coordinate layout''
    CoordinatorLayout coordinatorLayout;
    ...
    ...
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/white"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.0.2'
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha05'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'



}

build.gradle

anhgbhbe

anhgbhbe1#

您可以在<android.support.design.widget.CoordinatorLayout中添加坐标布局的id,如android:id="@+id/coordinator_layout"
所以它会起作用

8qgya5xd

8qgya5xd2#

当我加上

implementation 'androidx.coordinatorlayout:coordinatorlayout:<whatever the newest version is>'

我的模块依赖块。

相关问题