我正在使用倒数计时器的吐司,因此吐司应该每秒更改它的文本。我使用它来显示吐司正好1秒,但我希望吐司重复自己。希望我能让你理解。
toast = Toast.makeText(getApplicationContext(), text.getText().toString(), Toast.LENGTH_SHORT); toast.show();
Handler handler = new Handler();
handler.postDelayed
(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, 1000);
答案 0 :(得分:3)
这将在一秒钟内显示一个新的吐司。
int count = 100; //Declare as inatance variable
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
final Toast toast = Toast.makeText(
getApplicationContext(), --count + "",
Toast.LENGTH_SHORT);
toast.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, 1000);
}
});
}
}, 0, 1000);
答案 1 :(得分:0)
run()
。所以在那里举杯祝酒。
Handler handler = new Handler();
handler.postDelayed
(new Runnable() {
@Override
public void run() {
toast.cancel();
toast = Toast.makeText(getApplicationContext(), text.getText().toString(),Toast.LENGTH_SHORT);
toast.show();
}
}, 1000);
答案 2 :(得分:0)
这个page描述了一种保持吐司无限期显示的方法。因此,当您手头有吐司的文本视图时,您可以根据需要更改文本。
答案 3 :(得分:0)
覆盖此功能
@Override
protected void onHandleIntent(Intent intent) {
try {
Toast.makeText(context,"Click on Location button to find your bus !",Toast.LENGTH_LONG).show();
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
转到显示类型
转到启动器java类和
Intent intent = new Intent(this, Service_toast.class);
startService(intent);
====>>有关服务vist android devloper的更多信息: https://developer.android.com/guide/components/services.html