I am setting ContentView in MainActivity as
setContentView(R.layout.activity_main);
I have other module in package as well, for that module I defined in gradle file apply plugin: 'com.android.library'
This once also has res/layout/activity_main.xml
So can I call activity_main.xml from another module from MainActivity?
To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.
In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.
Under <merge/> tags, we can specify a part of the layout that has to come in the main layout. It is similar to the main layout having Button, TextView, etc., It can be specified in a meaningful android naming convention XML file. eg: custom_layout.
Yes you can, but your module must have another Android packageId (EDIT: just to make sure, you declare your packageId inside your Android manifest).
So e.g. you have com.example.app
for your app module and com.example.lib
for your library. Then you can access your resource ids by com.example.app.R
or com.example.lib.R
.
So you would have com.example.lib.R.layout.activity_main
for your layout inside your library module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With