I'm creating an app that lets you change the color of practically any part of the UI (any button, background, etc.). The nav drawer currently only has three states it switches between: Light, Dark, or Black. I've achieved this by using three separate identical activity_main layouts, their only difference being the nav drawer's background color in XML. It just loads the appropriate layout in setContentView depending on which theme the user has selected in the app's settings.
However, considering the fact that the user can set their app's background color to literally any color they want, it's a bit jarring when their background is, say, a light shade of blue, and the nav drawer is bright white. I would like to have a way to set the background of the drawer programmatically in Java so I can set it to whatever the user's background color is, or maybe a lighter/darker shade, etc.
My project's min API level is 21, and it's targeting API 30. I've looked through all the documentation I could find on the methods contained in the Navigation Drawer class, but I couldn't find anything to achieve this.
To clarify, the project is entirely in Java, so I probably won't understand any answers in Kotlin. However, any help is appreciated! Thank you in advance for any info anyone can provide.
I know it is Kotlin but the methods should be the same:
val navigationView = findViewById(R.id.nav_view)
navigationView.setBackgroundColor(Color.RED) // use your color here
And xml:
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"/>