膨胀类material.bottomnavigation.BottomNavigationView时出错

时间:2019-02-10 15:30:59

标签: java android bottomnavigationview androidx

我正在尝试实现BottomNavigationView,我知道关于同一问题有多个答案,但是似乎没有一个对我有用。

我遵循了这个doc

在预览模式下,出现此错误

ThisWorkbook.Worksheets(1).Range("K1").Value = False
    Do While ThisWorkbook.Worksheets(1).Range("K1").Value = False
    DoEvents
    Loop

当我运行TestActivity时,出现了使类膨胀的错误

  • 可绘制对象位于 res / drawable
  • 菜单位于 res /菜单

从不同帖子的答案中我可以理解,这是一个资源问题。

我试图删除每个资源调用,但是即使仅定义了宽度和高度,我仍然会收到错误消息。

TestActivity

IllegalArgumentException: Unknown color

test.xml

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import pt.myapp.android.myapp.R;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
    }
}

bottom_navigation_menu

<FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     mlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

<com.google.android.material.bottomnavigation.BottomNavigationView        
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_gravity="bottom"
    android:background="@color/colorPrimary"
    app:itemIconTint="@drawable/bottom_navigation_colors"
    app:itemTextColor="@drawable/bottom_navigation_colors"
    app:menu="@menu/bottom_navigation_menu" />

</FrameLayout>

bottom_navigation_colors.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

        <item
            android:id="@+id/nav_first_page"
            android:icon="@drawable/page"
            android:title="page"
            app:showAsAction="always" />

</menu>

渐变

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_checked="true"
        android:color="#ffffff" />
    <item
        android:state_checked="false"
        android:color="#ffffff" />
</selector>

错误

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'



android {
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    compileSdkVersion 28
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "pt.myapp.android.myapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 42
        versionName "v1.5.0d"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }

    signingConfigs {
        config {
            Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newDataInputStream())
            storeFile file(properties.getProperty('storeFile'))
            keyAlias properties.getProperty('keyAlias')
            storePassword properties.getProperty('storePassword')
            keyPassword properties.getProperty('keyPassword')
        }
    }

    dataBinding {
        enabled = true
    }

    buildTypes {
        release {
            signingConfig signingConfigs.config
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            proguardFile "proguard-butterknife-7.pro"
            proguardFile "proguard-google-play-services.pro"
            proguardFile "proguard-support-v7-appcompat.pro"
            proguardFile "proguard-joda.pro"
        }
        debug {
            debuggable true
            signingConfig signingConfigs.config
            applicationIdSuffix ".debug"
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':FloatingView')


    implementation 'de.hdodenhof:circleimageview:2.2.0'

    /* Multidex */
    implementation 'androidx.multidex:multidex:2.0.1'


    implementation 'com.github.lzyzsd:circleprogress:1.2.1'

    /* FACEBOOK  */
    implementation 'com.facebook.android:facebook-android-sdk:4.35.0'
    implementation 'com.facebook.android:facebook-login:4.35'


    implementation 'com.github.wrdlbrnft:sorted-list-adapter:0.2.0.1'
    implementation 'com.github.chrisbanes:PhotoView:1.3.0'
    implementation 'com.scottyab:aescrypt:0.0.1'
    implementation 'com.github.traex.rippleeffect:library:1.3'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.miguelcatalan:materialsearchview:1.4.0'
    implementation 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'im.dacer:AndroidCharts:1.0.4'
    implementation 'com.github.greenfrvr:rubber-loader:1.1.2@aar'

    /* SUPPORT LIBRARY */
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "androidx.recyclerview:recyclerview:1.0.0"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.preference:preference:1.0.0"
    implementation "androidx.annotation:annotation:1.0.1"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.palette:palette:1.0.0"


    /* FIREBASE */
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    implementation 'com.google.firebase:firebase-core:16.0.7'

    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation "com.google.firebase:firebase-appindexing:17.1.0"
    implementation "com.google.firebase:firebase-auth:16.1.0"
    implementation "com.google.firebase:firebase-storage:16.0.5"
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
    implementation "com.google.firebase:firebase-ads:17.1.3"
    implementation "com.google.firebase:firebase-config:16.3.0"
    implementation "com.google.firebase:firebase-perf:16.2.3"
    implementation "com.google.firebase:firebase-database:16.0.6"
    implementation "com.google.firebase:firebase-appindexing:17.1.0"
    implementation 'com.firebaseui:firebase-ui-storage:0.6.0'



    // Room components
    implementation "androidx.room:room-runtime:2.1.0-alpha04"
    annotationProcessor "androidx.room:room-compiler:2.1.0-alpha04"
    androidTestImplementation "androidx.room:room-testing:2.1.0-alpha04"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"


    /* Retrofit */
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:retrofit-converters:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'


    implementation 'joda-time:joda-time:2.9.9'    
    testImplementation 'junit:junit:4.12'

    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

    debugImplementation 'com.sothree.slidinguppanel:library:3.3.1'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"


    kapt "com.android.databinding:compiler:3.3.0-alpha08"

}

kapt {
    generateStubs = true
}

apply plugin: 'com.google.gms.google-services'
repositories {
    mavenCentral()
}

4 个答案:

答案 0 :(得分:2)

使用活动主题Theme.MaterialComponents.DayNight

答案 1 :(得分:0)

BottomNavigationView中,由于XML可能导致膨胀错误,它可能位于@layout@drawable@style@color文件夹中。

<com.google.android.material.bottomnavigation.BottomNavigationView        
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:itemIconTint="@drawable/bottom_navigation_colors"
app:itemTextColor="@drawable/bottom_navigation_colors"
app:menu="@menu/bottom_navigation_menu" />

此行可能引起充气错误: app:menu="@menu/bottom_navigation_menu"

我通过将可绘制文件保存在两个文件夹中来解决了该问题:

  1. 可绘制
  2. drawable-v24

答案 2 :(得分:0)

请确保将可绘制对象放在res/drawable文件夹中,而不要放在res/drawable-24中。我遇到了类似的问题,并且通过将文件移动到res/drawable文件夹中,错误消失了。

答案 3 :(得分:0)

采用您的样式,然后删除“ android:textColorSecondary”。 这应该可以解决您的问题。