Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在做一个项目,我目前正试图在应用程序操作栏中放置一个开关(如在 wi-fi 设置中: http: //tinypic.com/r/2l8vt35/6)
如何才能做到这一点?
添加android:actionLayout到您<item>的菜单 XML 资源中,指向一个布局 XML 资源,该资源具有您的Switch. 然后,使用getActionView()onMenuItem来注册监听器以了解交换机的变化。
android:actionLayout
<item>
Switch
getActionView()
MenuItem
请注意,Switch仅适用于 API 级别 14 及更高级别。