On/Off Toggle Button in Preferences & Action Bar - Ice Cream Sandwich Style

ε祈祈猫儿з 提交于 2019-12-04 10:15:36

问题


I am referring to the blue ON/OFF styling as seen in the default Android Settings app on ICS phones. It can also be seen here: http://android-developers.blogspot.com/2012/02/android-design-v2-now-with-stencils.html I want to put them in a Preference screen, would I have to use a custom preference widget?

Also, is it easy to put toggle buttons in the Action Bar? It seems to be possible since it is done for Wifi Settings in the default Android Settings on ICS, but it is probably a custom menu item?

Any help is greatly appreciated.


回答1:


As easy as:
My xml-v14/preferences.xml

<SwitchPreference
    android:key="@string/feature_id"
    android:title="@string/feature_title" />

For compatibility:
My xml/preferences.xml

<CheckBoxPreference 
    android:key="@string/feature_id"
    android:title="@string/feature_title" />


来源:https://stackoverflow.com/questions/9970269/on-off-toggle-button-in-preferences-action-bar-ice-cream-sandwich-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!