Search code examples
javaandroidandroid-layoutlayout

How can do I create layout for each activity in Android?


I specially created a bottom bar design. I have 3 activities and for each activity, the background of the menu in this bottom bar will change, for example; While the user is in 1.activty, the background of the 1st menu in the bottomBar will change, then the background of the 2nd menu in the bottomBar will change when in 2.activty

it is very difficult to do this for every activity and sometimes it can get messy so I want to make a design and a module where this design is managed. but i don't know how i can do this.. i would be very happy if you give an example. (whichever button is pressed needs to go to that activity and change the background) Please review;

Activity 1

Activity 2


Solution

  • You shouldn't be making separate versions of that for each Activity. That should be a single custom View, with one view set as the selected view which gets a dark background. Then you just need to include that custom view in each of the 3 activities with the proper view set as selected. Then you have 1 java class defining the custom view, 1 xml file defining the layout of this view, and in each activity's xml file you include this view.