开发者

How to hide imagebutton?

I have 1 imageButton and i want to hide that button after 5sec in oncreate开发者_开发百科 method. Can anyone please help me


onCreate(){
  new SleepTask().execute();
}

private class SleepTask extends AsyncTask{
  protected void doInBackground(){
    Thread.sleep(5000);
  }
  protected void onPostExecute(){
    yourImageButton.setVisiblity(View.INVISIBLE);
  }
}


ImageButton inherits from View so you can always use:

imageButton.setVisibility(View.INVISIBLE);

In order to have the view disappear after x amount of time you can use a handler

Handler handler = new Handler();
handler.postDelayed( new Runnable() {

   public void run(){
       imageButton.setVisibility(View.INVISIBLE);
   } 

}, 5000);//delayed 5 secs

Ensure to call this after you are done with everything of the view and after setContentView or onViewCreated (for fragments) is called


imageButton.setVisible(View.INVISIBLE); or imageButton.setVisible(View.GONE);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜