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

查看:231
本文介绍了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,你可以看看<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/2.0_r1/com/android/phone/InCallMenuView.java"相对=nofollow> 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.

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

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