How to hide the image button?

I have 1 imageButton and I want to hide this button after 5 seconds in the oncreate method. Can anyone help me out?

+3
source share
3 answers
onCreate(){
  new SleepTask().execute();
}

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

ImageButton inherits View, so you can always use:

imageButton.setVisibility (View.INVISIBLE);

To disappear a view after x 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

Make sure you call this after the whole view is complete and after setContentView or onViewCreated (for fragments) is called

+3
source

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

+1

Source: https://habr.com/ru/post/1770460/


All Articles