简体   繁体   English

如何为 Android 中的每个活动创建布局?

[英]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 到该活动并更改背景)请查看;

Activity 1活动一

Activity 2活动二

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.

相关问题 如何创建活动的android快捷方式? - How do I create an android shortcut to an activity? 如何在android中创建自定义布局? - How can I create custom layout in android? “布局”是否与 Android Studio 中的“布局资源”相同? 如何以编程方式创建 XML 布局资源? - Is "layout" the same as "layout resource" in Android Studio? How can I programmingly create an XML layout resource? 如何在Android Studio中的活动中创建移动的背景图像 - How can I create a moving background image in an activity in android studio 我如何在 android studio 中创建历史布局,例如最近 - How I can create history layout in android studio such as recent 我如何在另一个活动中做一个动作?android - How i can Do an action in another activity ?android 当Android Activity失去焦点时,如何隐藏或显示布局元素? - How do I hide or show layout elements when an Android Activity goes out of focus? 如何在Android中为表单上的每个控件创建特定的键? - How do I create a specific key for each control on a form in Android? 如何为android创建可重用的小型布局,其中此布局的实例在单个页面上创建列表项 - How do I make a reusable small layout for android where instances of this layout create a list item on a single page 如何从Android的Activity类中引用另一个项目的layout / xml文件? - How can I refer to layout/xml files of another project from my Activity class in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM