Android的菜单项切换按钮

问题描述:

在我的Andr​​oid应用程序,我想设置为可切换的,在它的菜单,如拨号应用程序做的扬声器和静音。你可以看到下面的图片:

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:

您看到的扬声器,静音和保持选项切换按钮 - 您可以再次点击他们,他们将切换绿的颜色。他们可以这样做,在一个自定义的方式,但我怀疑它是一个选项(我尝试设置可检查的属性)。

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源$ C ​​$ C,你可以看看 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的一部分,但它看起来pretty的自足。如果你的项目有一个兼容的许可,您可以在您认为合适将它复制到你的项目和使用和修改它。

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.