百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

FaceOffToggleButton

> 编程语言
开源

切换按钮,当选中时显示一个快乐的面孔,否则显示不快乐的面孔。

383 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

切换按钮,当选中时显示一个快乐的面孔,否则显示不快乐的面孔。

FaceOffToggleButton

Toggle button which shows a happy face for checked or unhappy for unchecked.

Recently, I spent some time to finish a cute toggle button and after that, I found a toggle button design with a happy or unhappy face to show the checked status. Check here for the IOS version and here for the design in Dribbble. Since I have made a similar one, so I just change some codes to create the new FaceOffToggleButton(FOTB). This document is a quite simple one and for more information, please check JellyToggleButton.

Guide

  1. 中文文档
  2. Gradle
  3. Demo
  4. Usage Guide
    1. Background Color
    2. Left & Right Background Color
    3. Left & Right Face Color
    4. Left & Right Eye Color
    5. Left & Right Mouth Color
    6. Set Checked and Toggle
    7. Listener
    8. Duration
    9. Draggable
    10. Color Change Type
    11. Dimension
    12. Other Method
  5. Todo
  6. Versions
  7. License

Gradle

dependencies {
    compile 'com.nightonke:faceofftogglebutton:1.0.0'
}

Demo

Try demo:

  1. On Github
  2. On Fir

Usage Guide

Background Color

Notice that the background color here is totally different from the background color of a veiw. Try to set background color with the following method or check the source code and you will figure out why.

setBackgroundColor(int mBackgroundColor)
app:foBackgroundColor="@color/white"

Left & Right Background Color

The color of background when the face is on the end-of-left and end-of-right.

setLeftBackgroundColor(int mLeftBackgroundColor)
setRightBackgroundColor(int mRightBackgroundColor)
app:foLeftBackgroundColor="@color/gray"
app:foRightBackgroundColor="@color/blue"

Left & Right Face Color

The color of face when it is on the end-of-left and end-of-right.

setLeftFaceColor(int mLeftFaceColor)
setRightFaceColor(int mRightFaceColor)
app:foLeftFaceColor="@color/white"
app:foRightFaceColor="@color/white"

Left & Right Eye Color

FOTB has beautiful eyes.

setLeftEyeColor(int mLeftEyeColor)
setRightEyeColor(int mRightEyeColor)
app:foLeftEyeColor="@color/gray"
app:foRightEyeColor="@color/blue"

Left & Right Mouth Color

setLeftMouthColor(int mLeftMouthColor)
setRightMouthColor(int mRightMouthColor)
app:foLeftMouthColor="@color/gray"
app:foRightMouthColor="@color/blue"

Set Checked and Toggle

Method With Animation With Listener
setChecked(boolean checked) Y Y
setChecked(boolean checked, boolean callListener) Y Y/N
setCheckedImmediately(boolean checked) N Y
setCheckedImmediately(boolean checked, boolean callListener) N Y/N
toggle() Y Y
toggle(boolean callListener) Y Y/N
toggleImmediately() N Y
toggleImmediately(boolean callListener) N Y/N

Listener

fotb0.setOnStateChangeListener(new FaceOffToggleButton.OnStateChangeListener() {
    @Override
    public void onStateChange(float process, State state, FaceOffToggleButton fotb) {
        // process - current process of JTB, between [0, 1]
        // state   - current state of JTB, it is one of State.LEFT, State.LEFT_TO_RIGHT, State.RIGHT and State.RIGHT_TO_LEFT
        // fotb     - the FOTB
    }
});

Duration

setDuration(int duration)
app:foDuration="1000"

Draggable

setDraggable(boolean draggable)
app:foDraggable="false"

Color Change Type

For information, please check here.

setColorChangeType(ColorChangeType mColorChangeType)
app:foColorChangeType="hsv"

Dimension

// Radius of face, in pixel.
setFaceRadius(float mFaceRadius)

// The ratio for width to face radius, in float.
setWidthRadiusRatio(float mWidthRadiusRatio)

// The margin between face and background, in pixel.
setFaceMargin(float mFaceMargin)
app:foFaceRadius="15dp"
app:foWidthRadiusRatio="2.5"
app:foFaceMargin="1dp"

Other Method

The ratio for distance of finger movement to distance of face movement.

setTouchMoveRatioValue(float ratio)
app:foTouchMoveRatioValue="2"

Whether call listener when face moves to same state as last.

setMoveToSameStateCallListener(boolean callListener)
app:foMoveToSameStateCallListener="false"

Todo

  1. Ease out back effect of the eyes and mouth.
  2. More emoji.

Version

1.0.0

The first version.

License

Copyright 2016 Nightonke

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言