31

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

4

2 に答える 2

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);
于 2011-03-17T23:57:15.093 に答える
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>
于 2013-03-27T19:10:55.357 に答える