簡體   English   中英

適用於應用程序的Android常量菜單

[英]Android Constant Menu for app

我一直在這個網站和Google上四處逛逛,卻找不到任何能給我明確答案的東西。 所以我想我只是問問。 我是Android新手,所以最好有一個清晰的解釋。

問題很簡單。 我希望我的應用程序在底部可以有一個恆定的菜單,並且可以隨時進行活動。

例如,樂譜移動應用程序執行此操作,紅色箭頭指向我想要的內容:

捕獲

或者甚至可以使用更大的灰色菜單:

捕獲

請幫忙。

您可以使用片段來實現。 http://developer.android.com/guide/topics/fundamentals/fragments.html

當您的應用啟動時,您會加載一個稱為HomeActivity或其他的活動。 此活動應加載如下所示的布局:

<?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>

如您所見,您的3個按鈕始終位於屏幕底部。 不用調用其他活動,而是將RelativeLayout“ fragment_container”中的片段替換為要顯示的片段。 這意味着您必須使用“片段類”來更改“活動類”。 片段和活動非常安靜,因此更改代碼不應該很困難。

在Android中,用於顯示導航和操作項的首選方法是使用ActionBar,該模式具有一種稱為“拆分操作欄”的模式,可以在屏幕的頂部和底部進行拆分(通常沿着屏幕頂部和底部拆分)。最佳)。 這是專為您要描述的情況而設計的。 您可以在Android設計指南中閱讀有關操作欄的設計指南

要創建拆分操作欄,請從“ 開發人員指南”中

要啟用拆分操作欄,只需將uiOptions =“ splitActionBarWhenNarrow”添加到您或清單元素中。

請記住,根據設計指南,導航元素應位於頂部,而動作(播放,暫停,電子郵件等)應位於底部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM