Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 layouts 1 activity android

Tags:

android

I have a navigation bar in my app, the thing is that I want the navbar to be available in all activities. I suppose that I have to set contentView two times, but that doesn't work, of course.

I've been looking at and but I dont get it to work. I have a super class, can I set this second layout from my super class?

like image 849
madcoderz Avatar asked Dec 11 '25 04:12

madcoderz


1 Answers

You should include the nav bar via <include> tag from the other layouts. Setting the content layout twice will not work, as Android is in the callbacks basically always using what the user has told last. So

setContentLayout(R.layout.nav);
setContentLayout(R.layout.main);

will result in only the main layout being used.

Have a look at this article which gives an example of using the include tag.

like image 188
Heiko Rupp Avatar answered Dec 12 '25 19:12

Heiko Rupp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!