我怎样才能创建一个类似于Twitter的应用程序的位置切换​​按钮切换按钮?按钮、类似于、创建一个、应用程序

由网友(因为在乎才会乱想)分享简介:我应该使用什么自定义按钮,可滑动左右如开/关按钮的位置上Android的Twitter的应用程序,如下图:What custom button should I use which could be slided right and left such as on turn on/off location butto...

我应该使用什么自定义按钮,可滑动左右如开/关按钮的位置上Android的Twitter的应用程序,如下图:

What custom button should I use which could be slided right and left such as on turn on/off location button on android's twitter app as the picture below:

以及任何链接或引导创造这样的按钮?

and also any link or guide to create such button ?

感谢

推荐答案

使用一个简单的切换按钮与一个 StateListDrawable 设置为背景

Use a simple ToggleButton in combination with a StateListDrawable set as its background.

的样本切换按钮是可以找到的这里。

基本上你创建按钮选中和未选中状态的图像。您可以在 StateListDrawable ,并设置 StateListDrawable ToggleButtos 的背景。

Basically you create an image for the checked and unchecked state of the button. You set the appropriate images in the StateListDrawable and set that StateListDrawable as the ToggleButtos's background.