Android 操作栏抽屉切换自定义图标

Android 操作栏抽屉切换自定义图标,android,android-actionbar,drawertoggle,Android,Android Actionbar,Drawertoggle,我正在尝试使用操作栏抽屉切换,但我希望它显示的不仅仅是菜单图标。我希望它在自定义菜单图标的右上角显示通知计数,但我仍然希望操作栏抽屉切换在需要时显示后退箭头 因此,我首先尝试查看是否可以在操作栏抽屉切换上显示自定义布局(包含菜单图标的imageview和通知计数的textview),但没有成功 然后我尝试创建一个包含自定义菜单图标的菜单项。单击此菜单项时,我打开/关闭导航抽屉,但无法在菜单图标上显示包含我的通知的文本视图 欢迎提供任何帮助/想法:)尝试以下方法: ActionBar action

我正在尝试使用操作栏抽屉切换,但我希望它显示的不仅仅是菜单图标。我希望它在自定义菜单图标的右上角显示通知计数,但我仍然希望操作栏抽屉切换在需要时显示后退箭头

因此,我首先尝试查看是否可以在操作栏抽屉切换上显示自定义布局(包含菜单图标的imageview和通知计数的textview),但没有成功

然后我尝试创建一个包含自定义菜单图标的菜单项。单击此菜单项时,我打开/关闭导航抽屉,但无法在菜单图标上显示包含我的通知的文本视图

欢迎提供任何帮助/想法:)

尝试以下方法:

ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("hi");
        actionBar.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.actionbar_back_color));
        actionBar.setIcon(getResources().getDrawable(
                R.drawable.image_crush_home_drawar_icon));
        actionBar.setCustomView(R.layout.actionbar_right_two_icon);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(false);
布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/actionbar_back_color"
    android:orientation="horizontal"
    android:weightSum="6" >

    <LinearLayout
        android:id="@+id/line_search"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/image_action_"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_action" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/actionbar_title"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|left"
            android:singleLine="true"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/actionbar_text_color" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/line_search"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/image_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image_crush_home_search_icon" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/line_post_Message"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/image_next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image_crush_home_message_icon" />
    </LinearLayout>

</LinearLayout>


这几乎成功了,谢谢!但是,如何删除操作栏的左侧填充?我知道你可以在你给我的代码的根布局中放一个负的左边距,但是有没有更干净的方法呢?已经给出了很多答案相关的actionbar检查这些:和