2011-10-12 74 views
2

我使用下面的代碼隱藏了我的通知欄和標題欄。但是現在,我想創建這個通知欄和標題欄以響應觸摸。如果我觸摸我的模擬器屏幕,我想在顯示我的通知和標題欄後自動隱藏它們,當我觸摸時,只有我需要這個通知和標題欄。ontouch可以顯示我的notifacation欄和標題欄嗎?

requestWindowFeature(Window.FEATURE_NO_TITLE); 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 

這是我的xml文件..... 的main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/videoGrdVw" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:spacing="60px" 
    android:background="@drawable/bk1" 
    /> 
<LinearLayout 
    android:layout_height="100px" 
    android:id="@+id/Header" 
    android:background="@drawable/images1" 
    android:orientation="horizontal" 
    android:layout_alignParentTop="true" 
    android:layout_width="match_parent"> 

</LinearLayout> 
<LinearLayout 
    android:layout_height="100px" 
    android:layout_width="fill_parent" 
    android:background="@drawable/images2" 
    android:id="@+id/Footer" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    > 
</LinearLayout> 

</RelativeLayout> 

回答

1

您需要將主要佈局元素上創建一個onTouchListener。

這將:

  • 讓你捕捉觸摸事件爲您的應用佔據
  • 檢測向下和向上觸摸事件

像這樣的工作,在屏幕的整個部分:

mainlayout.setOnTouchListener(new OnTouchListener() { 
     @Override 
      public boolean onTouch(View v, MotionEvent event) { 
      if(event.getAction() == MotionEvent.ACTION_DOWN) { 
       //Code to ENABLE titlebar 
      } 
      else if(event.getAction() == MotionEvent.ACTION_UP) { 
       //Code to DISABLE titlebar 
      } 
      return false; 
    } 
}); 
+0

現在我更新我的問題.....我正在使用這種方式setContentView(R.layout.main );那麼如何使用這個代碼..... – balaji

+0

對不起,我不明白你在問什麼? – WilHall

相關問題