Я пытаюсь реализовать BottomNavigationView, я знаю, что есть несколько ответов на один и тот же вопрос, но ни один из них, похоже, не работает для меня.
Я следовал этому doc
В режиме предварительного просмотра я получаю эту ошибку
IllegalArgumentException: Unknown color
Когда я запускаю TestActivity, я получаю ошибку, надувающую класс
- Drawables находятся внутри res /drawable
- Меню внутри res / menu
Для того, что я смог понять из ответов в разных постах, это проблема ресурсов.
Я пытался удалить каждый вызов ресурса, но даже с указанием только ширины и высоты я все равно получаю сообщение об ошибке.
TestActivity
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);
}
}
test.xml
<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_menu
<?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>
bottom_navigation_colors.xml
<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>
gradle
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()
}
Ошибка
Process: pt.myapp.android.myapp.debug, PID: 13653
java.lang.RuntimeException: Unable to start activity ComponentInfo{pt.myapp.android.myapp.debug/pt.myapp.android.myapp.ui.activities.TestActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at pt.myapp.android.myapp.ui.activities.TestActivity.onCreate(TestActivity.java:13)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.getColorStateList(Resources.java:1031)
2019-02-10 14:47:12.350 13653-13653/pt.myapp.android.myapp.debug E/AndroidRuntime: at android.content.Context.getColorStateList(Context.java:642)
at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:67)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.createDefaultColorStateList(BottomNavigationMenuView.java:467)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:101)
at com.google.android.material.bottomnavigation.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:86)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:123)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:114)
... 28 more