android - Re-use of xml menu template with flavors -
i making app 3 flavors. using navigationview inside drawerlayout navigation. have specified menu xml in navigationview this:
... app:menu="@menu/activity_main_drawer" ... and goes 3 flavors. activity_main_drawer looks this:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkablebehavior="single"> <item android:id="@+id/nav_categories" android:title="categories" /> <item android:id="@+id/nav_map" android:title="map" /> </group> </menu> this used in starting, main activity called mainactivity. thing is, applications not supposed differentiate anyhow, except api url. now, need remove 1 of links 1 of apps.
the first solution come copy activity_main_drawer flavor specific resource menu folder , put android:visible="false" purpose, need maintain 2 menus (and possible forget update specific flavor one). cannot remove , <item> menu in flavor specific project, id won't available , application won't compile.
my other possibility remove item on run-time after have checked flavor app running.
i insight on approach better , how minimize number of code/text copied.
now, need remove 1 of links 1 of apps.
i going assume "links", mean 1 of <item> elements.
if so:
define
booleanresource, here calledi_can_haz_link,trueinmainsourcesetre-define same
booleanresourcefalsein flavor(s) should not have linkuse
android:visible="@bool/i_can_haz_link"in affected<item>
i go approach on either of 2 in question. of 2 in question, go duplicate menu resource, java code can remain clean , unaffected.
Comments
Post a Comment