Java 导航视图未知颜色
我是Android Studio的新手,正在尝试为我的应用程序添加一个侧导航栏。Java 导航视图未知颜色,java,android,navigation-drawer,Java,Android,Navigation Drawer,我是Android Studio的新手,正在尝试为我的应用程序添加一个侧导航栏。 但我收到了一个错误,说明该类 尚未实例化android.support.design.widget.NavigationView 我无法看到我的菜单或我创建的导航标题。 我以前在抽屉布局上也有同样的问题。 但我能够通过将build.gradle中的依赖项从'com.android.support:appcompat-v7:28.0.0-alpha3'和'com.android.support:design:28.0
但我收到了一个错误,说明该类 尚未实例化android.support.design.widget.NavigationView 我无法看到我的菜单或我创建的导航标题。
我以前在抽屉布局上也有同样的问题。
但我能够通过将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>
以下是我收到的错误:
这是读取异常实际有用的极少数情况之一:D 您的异常表示它无法确定您要使用的颜色。这是因为,正如@cricket_007所评论的,您的导航视图的
android:background
属性表示#ffff
,而不是#fff
或#ffff
干杯 将导航视图背景更改为
@android:color/white
如果这还不能解决问题,那么styles.xml中还有一些其他颜色无法解析额外的f on
#ffff
?嘿,伙计们,非常感谢你们。我一整天都在试图修复这个bug。我所要做的就是在styles.xml文件中更改颜色。再次感谢!!!!我相信ARGB值可以有4个字符,但我不确定alpha是否可以用于查看背景。非常感谢!!。我在styles.xml文件中编辑了我的颜色。成功了!!!非常感谢!!。我在styles.xml文件中编辑了我的颜色。成功了!!!
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'
}