【Android开发之《实现类似Toast可以自动消失的提示栏Tip》】沉舟侧畔千帆进,病树前头万木春。这篇文章主要讲述Android开发之《实现类似Toast可以自动消失的提示栏Tip》相关的知识,希望能为你提供帮助。
import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Context; import android.view.View; import android.widget.TextView; public class TipManager { private static final String TAG = TipManager.class.getSimpleName(); private Context mContext; private TextView mView; private Timer timer = null; private TimerTask cancelTask = null; public TipManager(Context context, TextView view) { mContext = context; mView = view; }public void init() { timer = new Timer(); }public void release() { if (cancelTask != null) { cancelTask.cancel(); cancelTask = null; }if (timer != null) { timer.cancel(); timer = null; } }public void show(CharSequence text) { // cancel hide task if (cancelTask != null) { cancelTask.cancel(); cancelTask = null; timer.purge(); }showUI(text); }public void show(CharSequence text, long duration) { showUI(text); // cancel hide task if (cancelTask != null) { cancelTask.cancel(); cancelTask = null; timer.purge(); }cancelTask = new TimerTask() { @Override public void run() { hideUI("default"); } }; timer.schedule(cancelTask, duration); }private void showUI(final CharSequence text) { ((Activity) mContext).runOnUiThread(new Runnable() { @Override public void run() { doShow(text); } }); }private void hideUI(final CharSequence text) { ((Activity) mContext).runOnUiThread(new Runnable() { @Override public void run() { doHide(text); } }); }private void doShow(CharSequence text) { mView.setText(text); mView.setVisibility(View.VISIBLE); }private void doHide(CharSequence text) { mView.setText(text); mView.setVisibility(View.INVISIBLE); } }
推荐阅读
- Android中View窗口getWidth和getMeasuredWidth的差别
- Android学习 多读官网,故意健康---手势
- Android开发之《RXJava的简单实现》
- 安卓io流再回顾
- 关于android中的单位(dpsp)
- SEAndroid安全机制框架分析
- 将HTML5封装成android应用APK文件的几种方法
- Android基础一
- android 自己主动拒接后再取消自己主动拒接,该联系人来电界面无图标显示,且点击挂断无反应