So I have a Navigation Drawer, the xml code for the drawer is as follows. The xml file is named navigation_drawer_header.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="@drawable/wallpaper">
<ImageView
android:layout_margin="40dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/company_logo"
android:id="@+id/navigation_header_logo"/>
</RelativeLayout>
Then my activity main calls the Nav Drawer in
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/navigation_view"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/drawer_menu">
</android.support.design.widget.NavigationView>
You'll notice that the nav drawer is implemented in the line
app:headerLayout="@layout/navigation_drawer_header"
So I want to change the background of the ImageView inside of my Nav Drawer, the one with id of navigation_header_logo. I have tried using
ImageView navImg = (ImageView) findViewById(R.id.navigation_header_logo);
navImg.setBackgroundResource(R.drawable.new_logo);
but that seems to crash the app. Can someone help?