The easiest? add an ImageView
or any View
with opaque background as the last element of your layout, with dimensions MATCH_PARENT
/ MATCH_PARENT
and Visibility GONE
.
When you want to show it, just call view.setVisibility(View.VISIBLE)
, or view.setVisiblity(View.GONE)
to hide it. It will come up above the rest of elements, which will be hidden under its opaque background.
View view=findViewById(R.id.yourSplashId);
show
view.setVisibility(View.VISIBLE);
hide
view.setVisibility(View.GONE);
I see in your question that you tried this approach and it didn't work. Maybe that View you generated was behind the fragment?
You can also put your Fragment + splash inside a ViewFlipper
<ViewFlipper>
<fragment>...</fragment>
<FrameLayout>
<imageView>
<progressbar> .. etc
</FrameLayout>
</ViewFlipper>
this has the added benefit that you can setup animations for transitions etc.. In this case:
ViewFlipper myFlipper=findViewById(R.id.myFlipper);
myFlipper.setDisplayedChild(0); // fragment
myFlipper.setDisplayedChild(1); // splash
and
myFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
myFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_out));