我在使用 Android L 中的 android.app.Notification.Builder.setVisibility() 时遇到问题。我已将 Android Studio 更新为 Beta,下载了 L SDK,并将我的 compileSdkVersion 和 targetSdkVersion 设置为 20。但 Android Studio 仍然可以t 解析 setVisibility 方法。
(编辑:我根据下面的评论更新了 compileSdkVersion 和 targetSdkVersion,并将我的支持库从 20.+ 更新到 21.+ )
如果没有 setVisibility() 行,我的代码将编译并运行。如果我尝试 NotificationCompat.Builder,我会得到同样的错误。
有谁知道如何解决这一问题?
android {
compileSdkVersion 'android-L' // was 20
buildToolsVersion '20'
defaultConfig {
minSdkVersion 13
targetSdkVersion 'L' // was 20
...
...
compile 'com.android.support:support-v13:21.+'
compile 'com.android.support:appcompat-v7:21.+'
import android.app.Notification;
...
noti = new Notification.Builder(InfoPanel.getContext())
.setContentTitle(notiTitle)
.setContentText("text")
.setSmallIcon(notifyIcon)
.setOngoing(true)
.addAction(firstActionIcon, firstActionText, firstActionPI)
.addAction(R.drawable.optionsmenuicon, InfoPanel.getContext().getString(R.string.options), piOptions)
.addAction(R.drawable.exit, InfoPanel.getContext().getString(R.string.remove), piExitNotification)
.setContentIntent(upperPendingIntent)
.setPriority(Notification.PRIORITY_HIGH)
.setVisibility(VISIBILITY_PUBLIC)
.build() ;
我收到 IDE 错误“无法解析方法 'setVisibility(?)'”和“无法解析符号 'VISIBILITY_PUBLIC'”
编辑:第一个 Gradle 构建错误“无法解析方法 'setVisibility(?)'”在我更新了 compileSdkVersion 后消失了,但它在 IDE 中仍然显示为红色。第二个错误仍然在这两个地方。