2012-02-17 22 views

回答

0

當頂部欄中顯示的項目多時,底部欄會被填滿。

而不是顯示「溢出」三點的項目將被放在底部欄。請記住在XML中的菜單項上使用:

android:showAsAction="ifRoom|withText" 

更多在這裏閱讀: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

+0

這看起來不對。在Google+示例中,它們頂部也有溢出圖標。 – PolandSpring 2012-02-17 22:11:46

+1

@kkshin這是一個自定義視圖,而不是默認的分割操作欄。 – doorstuck 2012-02-20 12:03:52

+0

我試過這個,但它只是在底部的操作欄中進行。 – Timmmm 2012-08-19 17:17:35

11

我不使用標準的動作條認爲這是可能的。當啓用拆分ActionBar時,ALL操作將顯示在屏幕的底部。

Google+應用「創建帖子」活動的底部欄似乎是自定義實現。注意長按以顯示動作標籤不起作用,即使切換到橫向時底部條仍然存在。位置項目是一個切換開關,它也是非標準的ActionBar行爲。

26

希望我的回答對你來說不算太晚。

  1. 使用android:uiOptions="splitActionBarWhenNarrow"(這增加了底部欄的東西)。
  2. 創建如下代碼的新佈局(此佈局將處理頂部欄上的所有項目)。

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" > 
    <Switch 
        android:id="@+id/switch1" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent"/> 
    <ImageButton 
        android:id="@+id/action_starred" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        style="?android:attr/actionButtonStyle" 
        android:src="@android:drawable/ic_menu_compass" 
        android:onClick="FakeMenu"/> 
    </LinearLayout> 
    
  3. 在您的活動粘貼此

    ActionBar actionBar = getActionBar();    
    actionBar.setCustomView(R.layout.actionbar_top); //load your layout 
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM); //show it 
    
  4. 這是所有:)

+0

你幫了我很多,謝謝!對於那些使用ActionBarSherlock庫的人來說,可以使用getSherlock()。getActionBar()來獲得您的操作欄對象。 – lopek 2013-06-01 23:11:14

+0

如何在頂部顯示流量菜單而不是底部? – samirprogrammer 2013-10-01 18:50:54

2

我有同樣的問題,沒有什麼,我發現真的工作,因爲我不得不處理隨着操作欄的縮小,然後在大型設備上,按鈕被放置在頂部而不是底部。所以,我終於解開了它在主要佈局放置一個「頁腳」:

Bottom ActionBar Example

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="false" 
     android:layout_above="@+id/footer"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:id="@+id/container" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="@dimen/body_padding_large" 
      android:paddingRight="@dimen/body_padding_large" 
      android:paddingTop="@dimen/body_padding_medium" 
      android:paddingBottom="@dimen/body_padding_medium" 
      android:gravity="top"> 

     </LinearLayout> 

    </ScrollView> 
    <LinearLayout android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     style="@android:style/ButtonBar"> 
     <Button android:id="@+id/btn_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button 1" /> 

     <Button android:id="@+id/btn_2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button 2" /> 
    </LinearLayout> 
</RelativeLayout> 
0
<?xml version="1.0" encoding="utf-8"?> 

< LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" > 

<Switch 
    android:id="@+id/switch1" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"/> 

<ImageButton 
    android:id="@+id/action_starred" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="?android:attr/actionButtonStyle" 
    android:src="@android:drawable/ic_menu_compass" 
    android:onClick="FakeMenu"/> 

</LinearLayout> 









//Then put these lines of code in your java class or activity 

    ActionBar actionBar = getActionBar();    
    actionBar.setCustomView(R.layout.actionbar); //load your layout 
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_USTOM); //show it 

//希望這有助於

+0

在這種情況下,如果您有權利,您可以投票回答(如果不需要評論)。 但是,如果您找到解決問題的另一種方法,請隨時分享。 – TocToc 2016-06-15 08:04:47