我試圖在屏幕上顯示一段文字一段時間,類似於吐司,但能夠指定確切的時間在屏幕上。我在想一個警告對話框可能適用於此,但我似乎無法弄清楚如何自動關閉對話框。設置時間後的Android隱藏對話框,如自定義時間間隔敬酒
你可以建議一個替代吐司通知,我可以在其中指定確切的時間顯示?
謝謝!
static DialogInterface dialog = null;
public void toast(String text, int duration) {
final AlertDialog.Builder builder = new AlertDialog.Builder(gameplay);
LayoutInflater inflater = (LayoutInflater) gameplay.getSystemService(gameplay.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.tutorial, (ViewGroup)gameplay.findViewById(R.id.layout_root));
((TextView)layout.findViewById(R.id.message)).setText(text);
builder
.setView(layout);
builder.show();
if (dialog!=null){
dialog.cancel();
dialog.dismiss();
}
dialog = builder.create();
Handler handler = null;
handler = new Handler();
handler.postDelayed(new Runnable(){
public void run(){
dialog.cancel();
dialog.dismiss();
}
}, 500);
}
@Javanator,感謝指出了這一點,我...我不知道我能/應該這樣做。 – 2011-03-01 04:09:16