错误与方法品牌和符号LENGTH_LONG在小吃吧
问题描述:
我试图表现出的小吃店错误与方法品牌和符号LENGTH_LONG在小吃吧
Snackbar.make(view.findViewById(android.R.id.content), "Message", Snackbar.LENGTH_LONG).show();
但有两个错误,我不知道为什么?
1.
Cannot resolve method 'make(android.view.View, java.lang.String, ?)'
2.
Cannot resolve symbol 'LENGTH_LONG'
UPDATE
的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.nispok:snackbar:2.6.1'
}
答
这是去的正确方法:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.1.0'
}
我也改变了compileSdkVersion
& buildToolsVersion
到最新版本最好选择最新的代码。如果你喜欢,也可以恢复到原来的状态。但DO请注意,始终保持compileSdkVersion
& buildToolsVersion
是相同的,即如果您选择23
选择两个都是23
,否则它会导致问题。
现在,来到SnackBar
,SnackBar
是Android设计库的一部分。你正在编译compile 'com.nispok:snackbar:2.6.1'
。请使用设计库:compile 'com.android.support:design:25.1.0'
。这应该可以解决问题。现在
,从你的活动,调用SnackBar
这样:
Snackbar.make(this.findViewById(android.R.id.content), "Message", Snackbar.LENGTH_LONG).show()
从你在哪里调用小吃吧? – OBX
@OBX来自非主要活动类别。当我从主要活动呼叫时,也会发生这些错误。 – SAM
'Snackbar.make(this.findViewById(android.R.id.content),“Message”,Snackbar.LENGTH_LONG).show();'你可以试试这个从活动,看看它的解决? – OBX