只能从同一库组调用Android P可见性awareimagebutton.setVisibility [英] Android P visibilityawareimagebutton.setVisibility can only be called from the same library group

查看:73
本文介绍了只能从同一库组调用Android P可见性awareimagebutton.setVisibility的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用com.google.android.material.floatingactionbutton.FloatingActionButton中的新Android P FloatingActionButton,并且收到此警告:

I'm trying to use the new Android P FloatingActionButton that's part of the com.google.android.material.floatingactionbutton.FloatingActionButton and I'm getting this warning:

VisibilityAwareImageButton.setVisibility只能从同一库组(groupId = com.google.android.material)调用

VisibilityAwareImageButton.setVisibility can only be called from the same library group (groupId=com.google.android.material)

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可见性更改:

I've tried searching and the only search result is in regards to responding to UI visibility changes:

https://developer.android.com/training/system-ui/visibility

我尝试探索如何查看该com.google.android.material程序包中是否有一个VISIBLE int值,而我发现的唯一一个是com.google.android.material.floatingactionbutton.FloatingActionButton.VISIBLE,但警告仍然存在.

I tried exploring how I could to see if there was a VISIBLE int value in that com.google.android.material package, and the only one I found was com.google.android.material.floatingactionbutton.FloatingActionButton.VISIBLE, but the warning still remains.

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
}

项目级build.gradle

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 Canary 14版本.似乎已经报告了该版本的一些错误,我怀疑这是其中之一.

edit:

I should note that I'm using Android Studio version 3.2 canary 14. It seems there have been some reported bugs for this version, and I suspect this is one of them.

Android Studio 3.2 Canary 15中仍然存在问题,但是我找到了使用show()hide()

Issue still exists with Android Studio version 3.2 canary 15, but I found a workaround for it using show() and hide()

override fun onCreate(savedInstanceState: Bundle?) {
    demoFab = findViewById(R.id.demoFab)
    demoFab.show()    // this works and doesn't have the warning
}

推荐答案

使用方法1

demoFab.show(); // in place of visible
demoFab.hide(); // in place of Invisible suppress the warning/error for me.

和方法2

@SuppressLint("RestrictedApi") // also suppressed the warning
private void setUp() {
    ....
}

更新:

方法3:

demoFab.setVisibility(View.GONE);
demoFab.setVisibility(View.INVISIBLE);
demoFab.setVisibility(View.VISIBLE);

方法4:

demoFab.visibility = View.GONE
demoFab.visibility = View.INVISIBLE
demoFab.visibility = View.VISIBLE

这篇关于只能从同一库组调用Android P可见性awareimagebutton.setVisibility的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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