[英]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;
我有 3 个活动,对于每个活动,这个底部栏中的菜单背景会发生变化,例如; 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
当用户在 1.activty 时,bottomBar 中的第一个菜单的背景会发生变化,然后在 2.activty 时 bottomBar 中的第二个菜单的背景会发生变化
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;
(无论按下哪个按钮都需要 go 到该活动并更改背景)请查看;
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.
然后您只需要在 3 个活动中的每一个活动中包含该自定义视图,并选择适当的视图集。 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.
然后,您有 1 个 java class 定义自定义视图,1 个 xml 文件定义此视图的布局,并且在每个活动的 xml 文件中包含此视图。
The best way to handle this scenario would be to use 3 fragments instead of Activities.处理这种情况的最佳方法是使用 3 个片段而不是活动。 That way the bottombar will be common and you can control its views directly in the activity.
这样底部栏将是通用的,您可以直接在活动中控制其视图。 You can use viewPager or Navigation Component to manage the navigation between the Fragments.
您可以使用 viewPager 或 Navigation Component 来管理 Fragment 之间的导航。 You can checkout this link for Navigation Components
您可以查看此链接以获取导航组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.