Android 菜单项切换按钮 [英] Android MenuItem Toggle Button

查看:26
本文介绍了Android 菜单项切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用程序中,我希望在其菜单中设置一个可切换的设置,就像拨号器应用程序为扬声器和静音所做的那样.你可以看到下面的图片:

In my Android application, I want a setting to be toggleable in it's menu like the Dialer app does for speaker and mute. You can see a picture below:

http://www.isaacwaller.com/images/acall.png

您会看到扬声器"、静音"和保持"选项是如何切换按钮的 - 您可以再次点击它们,它们将切换为绿色.他们可能会以自定义方式执行此操作,但我怀疑这是一个选项(我尝试设置 Checkable 属性).

You see how the Speaker, Mute and Hold options are toggle buttons - you can tap them again and they will toggle the green color. They may do this in a custom way, but I suspect it is a option (I tried setting the Checkable attribute).

推荐答案

看起来这个菜单项是作为自定义视图实现的.

It's looks like this menu item is implemented as a custom view.

在android源代码中你可以看看com.android.phone.InCallMenuView.java 看看这是如何实现的.

In the android source code you can take a look at com.android.phone.InCallMenuView.java to see how this is implemented.

它看起来不像是公共 API 的一部分,但它看起来非常独立.如果您的项目具有兼容的许可证,您可以将其复制到您的项目中,并根据需要使用和修改它.

It doesn't look like it is part of the public API, but it looks pretty self-contained. If your project has a compatible license, you may be able to copy it into your project and use and modify it as you see fit.

这篇关于Android 菜单项切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆