android 自定义抽屉,android – 动作栏抽屉切换自定义图标

在Android应用中,开发者试图在操作栏的抽屉切换按钮上同时显示自定义菜单图标和通知计数。他们尝试了设置自定义布局和创建带有菜单图标的菜单项,但未能实现预期效果。提供的代码片段展示了如何设置自定义布局,并通过ActionBar调整标题、背景、图标等,但未明确说明如何成功添加通知计数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

因此,我首先尝试在操作栏抽屉切换时显示自定义布局(包含我的菜单图标的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);

布局文件:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@color/actionbar_back_color"

android:orientation="horizontal"

android:weightSum="6" >

android:id="@+id/line_search"

android:layout_width="0dip"

android:layout_height="match_parent"

android:layout_weight="1"

android:gravity="center"

android:orientation="vertical" >

android:id="@+id/image_action_"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/icon_action" />

android:layout_width="0dip"

android:layout_height="match_parent"

android:layout_weight="3"

android:orientation="vertical" >

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

android:id="@+id/line_search"

android:layout_width="0dip"

android:layout_height="match_parent"

android:layout_weight="1"

android:gravity="center"

android:orientation="vertical" >

android:id="@+id/image_search"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/image_crush_home_search_icon" />

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

android:id="@+id/image_next"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/image_crush_home_message_icon" />

标签:android,android-actionbar,drawertoggle

来源: https://codeday.me/bug/20190624/1278371.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值