2011-03-15 21 views
31

HonycombのActionBarの左側にいくつかのメニュー項目を配置したいが、これを行う方法を示すドキュメンテーションは見つかりませんでした。連絡先アプリにはナビゲーションバーのすぐ左に検索があるので、これは可能なようです。どのように左側にメニュー項目を設定するための任意のアイデア?HoneycombのActionBarの左側にメニュー項目を配置する

答えて

16

ActionBarは、アプリケーションアイコンと通常のActionBarアイコンの間のカスタムレイアウトをサポートしています。例:ここ

// Set the custom section of the ActionBar with Browse and Search. 
ActionBar actionBar = getActionBar(); 
mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null); 
actionBar.setCustomView(mActionBarView); 
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
+0

カスタムかどうかを判断するにはどうすればよいの活動に私はこれを持っていますビューはActionBarでクリックされましたか? – CACuzcatlan

+0

私はこれを試しましたが、もはや私の家のアイコンを表示しません。 – CACuzcatlan

+0

@CACuzcatlan、actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);を使用してください。 –

15

は夢のように私のためにどのような作品です:

//hiding default app icon 
ActionBar actionBar = getActionBar(); 
actionBar.setDisplayShowHomeEnabled(false); 
//displaying custom ActionBar 
View mActionBarView = getLayoutInflater().inflate(R.layout.my_action_bar, null); 
actionBar.setCustomView(mActionBarView); 
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM) 

my_action_bar.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/turquoise"> 

    <ImageButton 
     android:id="@+id/btn_slide" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:background="@null" 
     android:scaleType="centerInside" 
     android:src="@drawable/btn_slide" 
     android:paddingRight="50dp" 
     android:onClick="toggleMenu" 
     android:paddingTop="4dp"/> 
</RelativeLayout> 
関連する問題