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 boolean resource, here called i_can_haz_link, true in main sourceset

  • re-define same boolean resource false in flavor(s) should not have link

  • use 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -