如何使文本仅淡出 20 秒,然后在单击按钮时消失
这是代码
public void scoreOpenB(View v) {
findViewById(R.id.main_mess).setVisibility(View.GONE);
((TextView)findViewById(R.id.main_mess)).setText(R.string.btn_closs);
findViewById(R.id.main_mess).setVisibility(View.VISIBLE );
}
}
您可以使用 AsyncTask 在延迟后更新 UI。试试这个 ;)
public void scoreOpenB(View v) {
View updateMe = findViewById(R.id.main_mess);
updateMe.setVisibility(View.GONE);
new UpdateUI().execute(updateMe);
}
}
private class updateUI extends AsyncTask<View, Integer, Long> {
View toUpdate;
protected void doInBackground(View view) {
toUpdate = view;
try {
Thread.sleep(20000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Long result) {
(toUpdate(TextView)).setText(R.string.btn_closs);
toUpdate.setVisibility(View.VISIBLE);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句