How can I make an activity temporarily not touchable and not 开发者_如何学Pythonfocusable ?
You can turn off all the listeners when you want. Another approach I have used is to use a transparent Linear Layout or Relative Layout to be inflated to cover the full screen for a period of time.
public void coveredScreen(){
if(point_total>0){
parent = (RelativeLayout) findViewById(R.id.main_view); //whatever your layout is
loadedView = getLayoutInflater().inflate(R.layout.covered_screen, null); //the layout that contains something that fills parent.
parent.addView(loadedView);
updateHandler = new Handler();
updateHandler.postDelayed(coveredScreen, 2000); //opens layout for 2000 ms
// turns off listeners...
button1.setClickable(false);
button2.setClickable(false);
}
Runnable loadingScreen = new Runnable() {
public void run() {
// this turns on listeners and removes the inflated view
parent.removeView(loadedView);
button1.setClickable(true);
button2.setClickable(true);
// Call this method again every 3 seconds if desired or as long as wanted by uncommenting this handler
//updateHandler.postDelayed(this, 3000);
}
};
So... to set this going for as long as you'd like then call everytime you want to block any actions from the user within the Activity.
精彩评论