代码:
/**
* 短时间(1s)显示toast提示框,此提示框会显示在Activity的中部
* 尽量少用
*
* @param word Created by cong on 2017/11/24 19:14
*/
public void toastShorter(final int word) {
this.runOnUiThread(new Runnable() {
public void run() {
final Toast toast = Toast.makeText(mContext, word, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
new Handler().postDelayed(new Runnable() {
public void run() {
toast.cancel();
}
}, 1000);
}
});
}
分析:toast.show()会超过2s,但是我在1s时就取消了toast