【Android工具类】用户输入非法内容时的震动与动画提示——EditT
发布时间:2020-12-15 03:23:34 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 /* * Copyright (c) 2014,青岛司通科技有限公司 All rights reserved. * File Name:EditTex
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考
转载请注明出处:
http://blog.csdn.net/zhaokaiqiang1992
/* * Copyright (c) 2014,青岛司通科技有限公司 All rights reserved. * File Name:EditTextShakeHelper.java * Version:V1.0 * Author:zhaokaiqiang * Date:2014-11-21 */ package com.example.sharkdemo; import android.app.Service; import android.content.Context; import android.os.Vibrator; import android.view.animation.Animation; import android.view.animation.CycleInterpolator; import android.view.animation.TranslateAnimation; import android.widget.EditText; /** * * @ClassName: com.example.sharkdemo.EditTextShakeHelper * @Description:输入框震动效果帮助类 * @author zhaokaiqiang * @date 2014-11-21 上午9:56:15 * */ public class EditTextShakeHelper { // 震动动画 private Animation shakeAnimation; // 插值器 private CycleInterpolator cycleInterpolator; // 振动器 private Vibrator shakeVibrator; public EditTextShakeHelper(Context context) { // 初始化振动器 shakeVibrator = (Vibrator) context .getSystemService(Service.VIBRATOR_SERVICE); // 初始化震动动画 shakeAnimation = new TranslateAnimation(0,10,0); shakeAnimation.setDuration(300); cycleInterpolator = new CycleInterpolator(8); shakeAnimation.setInterpolator(cycleInterpolator); } /** * 开始震动 * * @param editTexts */ public void shake(EditText... editTexts) { for (EditText editText : editTexts) { editText.startAnimation(shakeAnimation); } shakeVibrator.vibrate(new long[] { 0,500 },-1); } } ? ? 代码非常的少哈,而且为了使用起来更加方便,我直接把动画的设置写在代码里面了,这样就不需要额外的xml文件了。 if (TextUtils.isEmpty(et.getText().toString())) { new EditTextShakeHelper(MainActivity.this).shake(et); } 使用之前不要忘记加上震动的权限 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |