NavigationalView 未知颜色
NavigationalView unknown color
我是 Android Studio 的新手,我正在尝试为我的应用程序添加侧边导航栏。
但是我收到一条错误消息,指出 class
android.support.design.widget.NavigationalView 尚未实例化。
我看不到我创建的菜单或导航 header。
我之前的抽屉布局也有同样的问题。
但是我能够通过将 build.gradle 中的依赖项从 'com.android.support:appcompat-v7:28.0.0-alpha3' 和 'com.android.support:design:28.0.0-alpha3' 更改为 'com.android.support:appcompat 来解决它-v7:28.0.0-alpha1'和'com.android.support:design:28.0.0-alpha1'.
现在我正在尝试用我的导航视图修复错误。
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey">
<android.support.design.widget.NavigationView
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="#ffff"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_menu"/>
</FrameLayout>
这是我的 build.gradle 依赖项:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.bah.myapplication"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
这是我收到的错误:
这是阅读异常 实际上 有帮助的罕见情况之一 :D
您的异常表示无法确定您尝试使用的颜色。这是因为,正如@cricket_007 评论的那样,您的 NavigationView 的 android:background
属性表示 #ffff
而不是 #fff
或 #ffffff
.
干杯!
将导航视图背景更改为@android:color/white
如果这不能解决问题,则您的 styles.xml 中还有一些其他颜色无法解析
我是 Android Studio 的新手,我正在尝试为我的应用程序添加侧边导航栏。
但是我收到一条错误消息,指出 class
android.support.design.widget.NavigationalView 尚未实例化。
我看不到我创建的菜单或导航 header。
我之前的抽屉布局也有同样的问题。
但是我能够通过将 build.gradle 中的依赖项从 'com.android.support:appcompat-v7:28.0.0-alpha3' 和 'com.android.support:design:28.0.0-alpha3' 更改为 'com.android.support:appcompat 来解决它-v7:28.0.0-alpha1'和'com.android.support:design:28.0.0-alpha1'.
现在我正在尝试用我的导航视图修复错误。
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey">
<android.support.design.widget.NavigationView
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="#ffff"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_menu"/>
</FrameLayout>
这是我的 build.gradle 依赖项:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.bah.myapplication"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
这是我收到的错误:
这是阅读异常 实际上 有帮助的罕见情况之一 :D
您的异常表示无法确定您尝试使用的颜色。这是因为,正如@cricket_007 评论的那样,您的 NavigationView 的 android:background
属性表示 #ffff
而不是 #fff
或 #ffffff
.
干杯!
将导航视图背景更改为@android:color/white
如果这不能解决问题,则您的 styles.xml 中还有一些其他颜色无法解析