2014-05-13 47 views
7

我有一個動作sherlock欄,我需要自定義該控件,如下圖所示。我需要一個僞代碼或類似的簡單例子。我下載了圖書館,例子,我一直在搜索這個網站和谷歌,但我找不到像這樣的東西。 對不起,如果信息不完整,在這種情況下,我將編輯與您需要的信息的職位。謝謝。在Android中使用ActionbarSherlock和jeremyfeinstein slidingmenu自定義ActionBar

注:

  1. 我不想使用android.support.v4.widget.DrawerLayoutActionBarDrawerToggle。我需要sherlock滑動效果。
  2. 我需要一個圖像和標籤在菜單選項列表(LISTVIEW)之上(見右圖)。

enter image description here

今後我會需要像下面的條(方式必須類似於see this link

enter image description here

回答

3

實現「滑動菜單」這是完美的與Sherlock ActionBar

鏈接庫

https://github.com/jfeinstein10/SlidingMenu

VIDEOTUTORIAL爲實現兩個庫

https://www.youtube.com/watch?v=IW6idyV0CZQ

編輯

//pre-ICS 
if (actionBarSherlock instanceof ActionBarImpl) { 
    enableEmbeddedTabs(actionBarSherlock); 

//ICS and forward 
} else if (actionBarSherlock instanceof ActionBarWrapper) { 
    try { 
     Field actionBarField = actionBarSherlock.getClass().getDeclaredField("mActionBar"); 
     actionBarField.setAccessible(true); 
     enableEmbeddedTabs(actionBarField.get(actionBarSherlock)); 
    } catch (Exception e) { 
     Log.e(TAG, "Error enabling embedded tabs", e); 
    } 
} 

//helper method 
private void enableEmbeddedTabs(Object actionBar) { 
    try { 
     Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class); 
     setHasEmbeddedTabsMethod.setAccessible(true); 
     setHasEmbeddedTabsMethod.invoke(actionBar, true); 
    } catch (Exception e) { 
     Log.e(TAG, "Error marking actionbar embedded", e); 
    } 
} 

看看這個鏈接:

https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk

當你有你的動作條上的標籤,你可以ASING一個風格爲你的標籤,邊框,將backgroundImage,重力和你給按鈕的外觀。

看:

http://www.silverbaytech.com/2013/05/13/themes-for-the-android-actionbar-tabs/

試試吧,告訴我們。

+0

@Gaston F.是否有效?請接受我的答案,如果我幫你 – Aspicas

+0

謝謝你的鏈接,我已經看到了這些信息,這些庫和我已經安裝的例子,但我無法做screen2(通過鏈接的imagecontrol),我不能添加button1和按鈕2在頂欄上(見最後一張圖片)。如果您有解決方案,請欣賞幫助。謝謝 –

+0

你想要像「標籤」或只有一個圖標的按鈕按鈕? – Aspicas

7

SidingMenu佈局:

您應該設置一個ListView的菜單佈局。接下來,創建sliding_menu_header.xml佈局ImageViewTextView內:

<?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="wrap_content" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <ImageView 
      android:src="@drawable/image_source" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

    <TextView 
      android:text="text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

</LinearLayout> 

現在,你可以擡高這個佈局,並將其設置爲ListView的頭球觀點:

View menuHeader = getLayoutInflater().inflate(R.layout.sliding_menu_header, null); 
mListView.addHeaderView(menuHeader); 
mListView.setAdapter(mYourMenuAdapter); 

動作條的佈局:

您可以將自定義視圖添加到ActionBar。你的情況的佈局可以像:

<?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:gravity="center" 
    android:orientation="horizontal" > 

    <Button 
      android:id="@+id/button1" 
      android:text="button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

    <Button 
      android:id="@+id/button2" 
      android:text="button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

</LinearLayout> 

以下行然後添加到您的onCreate方法:

ActionBar actionBar = getSupportActionBar(); 
actionBar.setCustomView(R.layout.actionbar_view); 
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM 
     | ActionBar.DISPLAY_SHOW_HOME); 

Button button1 = actionBar.getCustomView.findViewById(R.id.button1); 
Button button2 = actionBar.getCustomView.findViewById(R.id.button2); 

希望這將有助於你。如果我的回答不完整,請發表評論,我會更新它。

1

從您的圖片中可以看出,您想要滾動操作欄。這是不可能的(據我所知)。對於類似這樣的工作,您必須製作自定義操作欄(作爲普通佈局),並處理可見性更改並自行滾動。您也可以檢查actionbar_compat(appcompat_v7)。如果基本上提供與ActionbarSherlock和SlidingMenu相同的功能。 http://android-developers.blogspot.ro/2013/08/actionbarcompat-and-io-2013-app-source.html。如果這是您的擔憂,菜單可以包含異質項目。

相關問題