0

I have an ImageButton (btnOpen), and I want to change its background, but just for a second, for example.

I know the method to do this (I use btnOpen.setBackgroundResource(my_resource); ), but how can I do that without making my UI non-responsive?

What's the best and simplest way, do I have to use something like Handler or runOnUIThread?

Thanks for help.

Kalem
  • 1,132
  • 12
  • 33

2 Answers2

0

One way to deal with this is to preload your ressource programmatically using a Handler.

I think this post can help you https://stackoverflow.com/a/12523109/665823

But usually if the UI is getting block by loading a single image ressource this means your ressource is too big. Try checking this out first.

Community
  • 1
  • 1
Kalem
  • 1,132
  • 12
  • 33
0

Use a handler

new android.os.Handler().postDelayed(new Runnable() {
  @Override
  public void run() {
      imageView.setBackgroundResource(R.drawable.something);
  }
}, 1000);
Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59