我必须创建一个通知,例如 Android Toast 通知,但我需要将其从服务中抛出,并且需要在需要时关闭它。 标准的 toast 通知就很完美,但太短了。
我尝试使用 DialogFragment,但它需要焦点(不像 toast),并且我无法将其从服务中抛出,而只能从 FragmentActivity 中抛出。
谢谢!!
最佳答案
Toast toast = new Toast(this);
TextView textView=new TextView(this);
textView.setTextColor(Color.BLUE);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setTextSize(20);
textView.setText("My Toast For Long Time");
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(textView);
timer =new CountDownTimer(20000, 1000)
{
public void onTick(long millisUntilFinished)
{
toast.show();
}
public void onFinish()
{
toast.cancel();
}
}.start();
关于java - 类似于 Toast 的通知,但持续时间更长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27037496/