问题
I have learned from this question that resources are globally shared in an Android Studio project.
I have a project with 3 activities (and more are coming), and I already find pretty messy to have access to every resources in any given activity.
Is there a way to allow an activity to access ids only from the associated layout ?
eg : I have MainActivity.java, activity_main.xml, Main2Activity.java, activity_main2.xml .
I would like to restrict the resources (mainly ids) accessible by MainActivity.java to activity_main.xml (so no access to resources from activity_main2.xml)
回答1:
No there is no way to do this. You can have source and resource sets based on Build variants but cannot tie up individual activities to resource files. But why do you need it. With a good naming convention, it would be pretty easy for you to co-relate the two and a layout gets attached to an activity only you use it as an argument to the setContentView
method.
来源:https://stackoverflow.com/questions/42026601/is-it-possible-to-separate-resources-access-in-android-studio