简体   繁体   English

适用于应用程序的Android常量菜单

[英]Android Constant Menu for app

I've been looking around on this site and on Google and haven't found anything that really gives me a clear answer. 我一直在这个网站和Google上四处逛逛,却找不到任何能给我明确答案的东西。 So I thought I'd just ask. 所以我想我只是问问。 I'm new to Android so a clear explanation would be best. 我是Android新手,所以最好有一个清晰的解释。

The question is simple. 问题很简单。 I want my app to have a constant menu at the bottom that I can use at any point, along with the activity behind it. 我希望我的应用程序在底部可以有一个恒定的菜单,并且可以随时进行活动。

For example, the score mobile app does this and the red arrow points to what I'd want: 例如,乐谱移动应用程序执行此操作,红色箭头指向我想要的内容:

捕获

Or Even this works with the bigger, grey menu: 或者甚至可以使用更大的灰色菜单:

捕获

Please help. 请帮忙。

You can achieve this by using Fragments. 您可以使用片段来实现。 http://developer.android.com/guide/topics/fundamentals/fragments.html http://developer.android.com/guide/topics/fundamentals/fragments.html

When your app starts up you load a single Activity called HomeActivity or whatever. 当您的应用启动时,您会加载一个称为HomeActivity或其他的活动。 This Activity should load a layout looking like this: 此活动应加载如下所示的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relativeLayout1"
        android:layout_alignParentTop="true" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >

        <Button
            android:id="@+id/btnFirst"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/btn_previous" />

        <Button
            android:id="@+id/btnSecond"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="@string/btn_pause" />

        <Button
            android:id="@+id/btnThird"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="@string/btn_next" />
    </RelativeLayout>

</RelativeLayout>

As you see, your 3 buttons are ALWAYS on the bottom of the screen. 如您所见,您的3个按钮始终位于屏幕底部。 Instead of calling different Activities you replace the Fragment in the RelativeLayout "fragment_container" with the Fragment you want to display. 不用调用其他活动,而是将RelativeLayout“ fragment_container”中的片段替换为要显示的片段。 That means that you have to change your Activity-Classes with Fragment-Classes. 这意味着您必须使用“片段类”来更改“活动类”。 Fragments and Activities are quiet similar and it shouldnt be very much hard to change your code. 片段和活动非常安静,因此更改代码不应该很困难。

In Android, the preferred method for displaying navigation and action items like that is to use the ActionBar, which has a mode called "split action bar", where it can be split across the top and bottom of the screen (typically it's just along the top). 在Android中,用于显示导航和操作项的首选方法是使用ActionBar,该模式具有一种称为“拆分操作栏”的模式,可以在屏幕的顶部和底部进行拆分(通常沿着屏幕顶部和底部拆分)。最佳)。 This is designed specifically for situations like the one you're describing. 这是专为您要描述的情况而设计的。 You can read about the design guidelines for the action bar in the Android Design Guide . 您可以在Android设计指南中阅读有关操作栏的设计指南

To create the split action bar, from the Dev Guide , 要创建拆分操作栏,请从“ 开发人员指南”中

To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your or manifest element. 要启用拆分操作栏,只需将uiOptions =“ splitActionBarWhenNarrow”添加到您或清单元素中。

Keep in mind that according to the design guide, navigation elements should be along the top bar, and actions (play, pause, email, whatever) should be along the bottom bar. 请记住,根据设计指南,导航元素应位于顶部,而动作(播放,暂停,电子邮件等)应位于底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM