简体   繁体   English

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

[英]Action Bar Drawer Toggle Custom Icon

I'm trying to use the action bar drawer toggle, but I would like it to display something more than just the menu icon. 我正在尝试使用操作栏抽屉切换,但我希望它显示的不仅仅是菜单图标。 I want it to display a notification count in the top right corner of my custom menu icon, but I still want the action bar drawer toggle to display the back arrow when needed. 我希望它在我的自定义菜单图标的右上角显示通知计数,但我仍然希望操作栏抽屉切换以在需要时显示后退箭头。

Therefore, I first tried to see if I could display a custom layout (containing an imageview for my menu icon and a textview for my notification count) on the action bar drawer toggle but whithout success. 因此,我首先尝试在操作栏抽屉切换时显示自定义布局(包含我的菜单图标的imageview和我的通知计数的textview),但是没有成功。

I then tried to create a menu item containing my custom menu icon. 然后我尝试创建一个包含我的自定义菜单图标的菜单项。 When this menu item is clicked, I open/close the navigation drawer, but I can't manage to display a textview containing my notification on the menu icon. 单击此菜单项时,我打开/关闭导航抽屉,但我无法在菜单图标上显示包含我的通知的文本视图。

Any help/idea is appreciated :) 任何帮助/想法表示赞赏:)

try these way: 尝试这些方式:

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);

layout file: 布局文件:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM