如何让活动暂时不可触及且无法集中精力?
答案 0 :(得分:0)
您可以根据需要关闭所有侦听器。 我使用的另一种方法是使用透明的线性布局或相对布局来充气以覆盖整个屏幕一段时间。
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);
}
};
所以......只要你想要设置它就可以在每次想要阻止活动中用户的任何动作时调用。