error: package android.support.design.widget does

2019-03-05 18:04发布

i'm new to android. when i want to import a project into my android studio it complain about this error that : error package android.support.design.widget does not exist

here is my code :

public class CatalogActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_catalog);

// Setup FAB to open EditorActivity
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
        startActivity(intent);
    }
});
}
}

and this is my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.example.android.pets"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:25.3.1'
     compile 'com.getbase:floatingactionbutton:1.9.1'
}

how can i solve this problem and one another thing that every time that i want to import another else project into my android studio there is bunch of error and need to change build.gradle and build.gradle.properties and every time i have some problem like this . can anyone give me a reference about this build.gradle to learn how it should be ?

4条回答
贪生不怕死
2楼-- · 2019-03-05 18:44

Floating action buttons are used for a special type of promoted action. so you need to add com.android.support:design library Include this line also in your build.gradle:

compile 'com.android.support:design:25.3.1'
查看更多
Animai°情兽
3楼-- · 2019-03-05 18:48

FloatingActionButton is available in com.android.support:design library. If you are using any class that class related libraries you need to include in build.gradle, that's why you are getting error.

查看更多
We Are One
4楼-- · 2019-03-05 18:56

Floating action buttons are used for a special type of promoted action. so you need to add com.android.support:design library Include this line also in your build.gradle:

compile this dependencies in your build.gradle:

compile 'com.android.support:design:25.3.1'
查看更多
欢心
5楼-- · 2019-03-05 19:03

Add following in gradle file :

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
查看更多
登录 后发表回答