2010-04-15 59 views
2

如何使活動暫時不可觸及且不可聚焦?Android禁用活動

+0

您希望活動保持活動狀態,但其用戶界面上的任何內容都不可觸摸或聚焦? – 2010-04-15 10:14:08

+0

是的,這正是我想要的... – Arutha 2010-04-15 10:29:13

+0

我需要一個方法,如setEnabled(false),但在一個活動 – Arutha 2010-04-16 09:50:40

回答

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); 
     } 
    }; 

因此,只要您希望在您希望阻止用戶在活動中執行任何操作時調用此功能。