最佳答案
我正在尝试使用新的 Android P FloatingActionButton,它是 com.google.android.material.floatingactionbutton.FloatingActionButton
的一部分,我收到了这样的警告:
SetVisiability 只能从相同的库组调用(groupId = com.google.android.Materials)
import com.google.android.material.floatingactionbutton.FloatingActionButton
import android.view.View
class MainActivity : AppCompatActivity() {
lateinit var demoFab: FloatingActionButton
override fun onCreate(savedInstanceState: Bundle?) {
demoFab = findViewById(R.id.demoFab)
demoFab.visibility = View.VISIBLE // the warning is here
}
}
我试过搜索,唯一的搜索结果是关于响应 UI 可见性变化的:
我试图探索如何能够看到,如果有一个 VISIBLE
整型值在该 com.google.android.material
包,我发现的唯一一个是 com.google.android.material.floatingactionbutton.FloatingActionButton.VISIBLE
,但警告仍然存在。
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:oss-licenses:0.9.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.oss.licenses.plugin'
android {
compileSdkVersion 'android-P'
defaultConfig {
applicationId "com.codeforsanjose.maps.pacmap"
minSdkVersion 21
targetSdkVersion 'P'
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
splits {
abi {
enable true
reset()
include 'arm64-v8a', 'armeabi', 'armeabi-v7a', 'mips', 'x86', 'x86_64'
universalApk false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.2'
//implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.5.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.13.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.13.0'
implementation 'com.google.android.gms:play-services-oss-licenses:15.0.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.moshi:moshi:1.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
}
我应该注意到我使用的是 Android Studio 版本3.2金丝雀14。这个版本似乎有一些错误报告,我怀疑这就是其中之一。
问题仍然存在于 Android Studio 版本3.2金丝雀15中,但我找到了使用 show()
和 hide()
的解决方案
override fun onCreate(savedInstanceState: Bundle?) {
demoFab = findViewById(R.id.demoFab)
demoFab.show() // this works and doesn't have the warning
}