【问题标题】:BottomAppBar throws IllegalArgumentExceptionBottomAppBar 抛出 IllegalArgumentException
【发布时间】:2018-11-26 04:13:23
【问题描述】:

我正在使用最新的Material Design android 库并按照this 文档创建BottomAppBar。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.ARFragment">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/blue"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是一个例外。完整日志为here

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
    at android.graphics.Canvas.checkValidClipOp(Canvas.java:779)
    at android.graphics.Canvas.clipRect(Canvas.java:826)
    at com.google.android.material.shape.MaterialShapeDrawable.prepareCanvasForShadow(MaterialShapeDrawable.java:850)
    at com.google.android.material.shape.MaterialShapeDrawable.draw(MaterialShapeDrawable.java:746)
    at android.view.View.getDrawableRenderNode(View.java:20463)
    at android.view.View.drawBackground(View.java:20399)

我看到了与此异常类似的其他 StackOverFlow 线程,但我没有答案,因为异常在库中。

我正在 Android P 上进行测试。

【问题讨论】:

  • 你见过this吗?

标签: java android material-design


【解决方案1】:

选中此项在 build.gradle 中包含 Google Maven 存储库。

allprojects {
repositories {
  jcenter()
  maven {
    url "https://maven.google.com"
  }
}
}

将材质组件依赖项放在 build.gradle 中。请记住,材料版本会定期更新。

implementation 'com.google.android.material:material:1.0.0-alpha1'

将 compileSdkVersion 和 targetSdkVersion 设置为针对 Android P 的最新 API 版本,即 28。

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.xxx"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 0
    versionName "1"

}

【讨论】:

  • 我的问题是没有使用最新版本。
猜你喜欢
  • 2014-09-18
  • 2014-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
相关资源
最近更新 更多