2012-11-15 17 views
8

enter image description here如何在SlidingMenu上放置一個ActionBar(如在Evernote應用程序中)?

我想製作具有類似於Evernote的ActionBar的滑動菜單。在這個應用程序,似乎它有2個ActionBars(我不知道它)。一個在主菜單,另一個在滑動菜單中。

無論如何建立這樣的2個ActionBars?或者它只是一個類似於ActionBar外觀的佈局安排。

感謝您的幫助和對我的英語感到抱歉。

ps。我使用ActionBarSherlock和SlidingMenu來實現這一點,但我無法找到像Evernote一樣的方式。

+0

AFAIK你可能想畫你的自我(第二看起來像一個actionbar) –

+0

嗯,好像我遇到了同樣的問題....我已經實施了滑動菜單上的操作欄,但我不能在後面的菜單上添加操作欄。 – Tkingovr

+0

@Sizer能幫我做出這種類型的菜單。我正在使用Jeremy Feinstein的SlidingMenu圖書館。但我無法做到這一點。你能給我這個滑動菜單的完整例子嗎? –

回答

1

好吧,我設法與貢納爾·卡爾鬆的幫助誰在正確的方向推了我不是一個搜索查看的

我實現了一個ImageButton的,像這樣做:

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#333333" > 

     <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="60dp" 
       android:src="@drawable/ic_launcher" 
       android:onClick="showPopup" /> 

</LinearLayout> 


<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/list_padding" 
    android:paddingRight="@dimen/list_padding" /> 

</LinearLayout> 

,並在我的mainActivity我只是拉這從谷歌的示例代碼創建一個彈出菜單:

public void showPopup(View v) { 
    PopupMenu popup = new PopupMenu(this, v); 
    MenuInflater inflater = popup.getMenuInflater(); 
    inflater.inflate(R.menu.actions, popup.getMenu()); 
    popup.show(); 
} 

和它的工作。謝謝Gunnar Karlsson。

9

您寫道:

我用(...)SlidingMenu

如果SlidingMenu你的意思是Jeremy FeinsteinSlidingMenu,並要使用這個菜單庫保管,你可以' t使用'真實'ActionBar,因爲SlidingMenu's菜單實現爲Fragment,在庫中名爲SlidingMenuFragment。 A Fragment不能容納ActionBar

您可以創建一個看起來像ActionBar的佈局。在SlidingMenuFragment's設置像這樣的佈局文件:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.sliding_menu,null); 

在菜單的佈局文件,這裏叫做sliding_menu.xml,比如,你可以做一個SearchView看起來它在ActionBar通過在頂部的佈局嵌套它。然後將該佈局的背景色/可繪製設置爲與列表的其餘部分不同。見下面的例子(我知道嵌套LinearLayouts不漂亮...只是使用了LinearLayoutSlidingMenu示例應用跨越的想法一個簡單的例子):

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#333333" > 

     <SearchView 
      android:id="@+id/searchView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingLeft="@dimen/list_padding" 
     android:paddingRight="@dimen/list_padding" /> 

</LinearLayout> 

這將是這樣的:

enter image description here

打開時,其中所述淺灰色框右邊是「真正的」 ActionBar的一部分。

編輯:您在評論中寫道:

的搜索查看示例工作遇到問題即時得到一個下拉菜單以相同的方式工作。

EverNote應用程序中的下拉菜單看起來像是以全息主題Spinner實現的。 Android Developers詳細說明了如何將Spinner添加到佈局的introduction。 Spinner的邏輯/ java代碼將被放置在SlidingMenuFragment中(如果使用SlidingMenu庫)。

+0

你可以推薦任何其他庫我沒有特別使用SlidingMenu,我只是發現它是最好的。 – Tkingovr

+0

我已經測試了此鏈接截至2012年8月的所有庫:http://stackoverflow.com/questions/8657894/android-facebook-style-slide/9905415#9905415爲我工作的應用程序。 Feinstein的SlidingMenu庫是我設法實現的唯一一個,其中客戶端需求爲1)菜單2上的類ActionBar搜索欄)當菜單打開時,ActionBar向右滑動,3)所有視圖都是Fragments。所以,網絡,我不能(因爲他們不爲我工作......)推薦另一個圖書館,但看看那個清單。 –

+0

好的謝謝你的幫助,我試圖實現一個菜單,就像在Evernote的應用程序,你會有什麼想法如何實現? searchView示例工程Im無法讓下拉菜單以相同的方式工作。 – Tkingovr

相關問題