包android.support.design.widget不存在 [英] package android.support.design.widget does not exist

查看:1706
本文介绍了包android.support.design.widget不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

build.gradle(module:app)

apply plugin: 'com.android.application'

  android {
        compileSdkVersion 29
        buildToolsVersion '29.0.2'

        defaultConfig {
            applicationId "com.example.android.miwok"
            minSdkVersion 15
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        } }


    dependencies {
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.1.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.2.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        'com.android.support:design:28.0.0'
        'com.google.android.material:material:1.0.0-'
        'com.android.support:support-v13:28.0.0'
        'com.android.support:support-annotations:28.0.0'
        'com.android.support:appcompat-v7:28.0.0' }

我的mainActivity.java

package com.example.android.miwok;


import android.os.Bundle; import
android.support.design.widget.TabLayout;

import androidx.appcompat.app.AppCompatActivity; import
androidx.viewpager.widget.ViewPager;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the content of the activity to use the activity_main.xml layout file
        setContentView(R.layout.activity_main);

        // Find the view pager that will allow the user to swipe between fragments
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);


        // Create an adapter that knows which fragment should be shown on each page
        CategoryAdapter adapter = new CategoryAdapter(this, getSupportFragmentManager());


        // Set the adapter onto the view pager
        viewPager.setAdapter(adapter);

        // Find the tab layout that shows the tabs
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

        // Connect the tab layout with the view pager. This will
        //   1. Update the tab layout when the view pager is swiped
        //   2. Update the view pager when a tab is selected
        //   3. Set the tab layout's tab names with the view pager's adapter's titles
        //      by calling onPageTitle()
        tabLayout.setupWithViewPager(viewPager);
    }
}

推荐答案

在您的代码中,您正在混合Support库和不允许的AndroidX库.删除support库并使用AndroidX.要正确迁移AndroidX,请执行以下步骤:

In your code you are mixing Support library with AndroidX library which is not permissible. Remove support library and use AndroidX. To migrate AndroidX correctly follow below steps:

从Android Studio菜单

From Android Studio Menu

  1. 选择重构->迁移至AndroidX
  2. 执行重构
  1. Select Refactor -> Migrate to AndroidX
  2. Press Do Refactor

这篇关于包android.support.design.widget不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆