2011-02-04 3 views
0

Android Theme.NoTitleBar.Fullscreen 테마를 사용하여 제목 및 상태 표시 줄을 비활성화하는 전체 화면 그리기 앱이 있습니다. 내가 얻고 자하는 요청 중 하나는 이러한 UI 요소를 자동 숨김으로 설정하는 기능입니다. 즉, 사용자가 터치 할 위치 근처에서 터치하는 것처럼 표시됩니다. 제목 표시 줄을 에뮬레이트하는 사용자 지정 Activity를 사용하여이 작업을 수행하는 방법을 상상할 수 있지만 알림 표시 줄을 바꿀 수는 없습니다.Android : 제목/상태 표시 줄 자동 숨기기 기능?

그래서 OS 표준 제목 및 상태 표시 줄을 자동 숨기기위한 방법이 있는지 궁금합니다. 이 요소가 onCreate의 Activity에 묶여 있거나 (또는 ​​onCreate의 XML에서 비정상적으로 보이기 때문에) 이것이 NO라면 상상할 수 있습니다. 한 번 활성화되면 해당 동작을 변경할 수 없습니다.

답변

0

그래서 OS 표준 제목과 상태 표시 줄을 자동으로 숨길 수있는 방법이 있는지 궁금합니다.

본 적이 없습니다.

또한 사용자가 요청하는 것은 일반적으로 수행 할 수 없습니다. 버튼이 "가까이있을"경우 어떻게해야합니까? 안드로이드 3.1을 사용하여

+0

그래, 그건 내 느낌이었고, 더 동의 할 수는 없지만, 나는 그것을 들여다 보겠다고 그들에게 말했다. –

4

, 하나는 상태 표시 줄이 될 경우, 줄이 나타납니다 접촉에

View.setSystemUiVisibility(View.STATUS_BAR_HIDDEN); 

사용하여 UI 상태 표시 줄의 표시 여부를 설정할 수 있습니다.

당신은

View.setOnSystemUiVisibilityChangeListener 

방법을 통해이 수신하고 나서이 문제에 대한 해결책은 바로 안드로이드 스튜디오가 가지고있는 더미 전체 화면 프로젝트에 생각하는 시간이

0

후 다시 줄을 숨길 수 있습니다. 그것을 밖으로 체크하십시오 :

public class FullscreenActivity extends Activity { 
     /** 
     * Whether or not the system UI should be auto-hidden after 
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. 
     */ 
     private static final boolean AUTO_HIDE = true; 
     /** 
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after 
     * user interaction before hiding the system UI. 
     */ 
     private static final int AUTO_HIDE_DELAY_MILLIS = 3000; 

     /** 
     * If set, will toggle the system UI visibility upon interaction. Otherwise, 
     * will show the system UI visibility upon interaction. 
     */ 
     private static final boolean TOGGLE_ON_CLICK = true; 

     /** 
     * The flags to pass to {@link SystemUiHider#getInstance}. 
     */ 
     private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION; 

     /** 
     * The instance of the {@link SystemUiHider} for this activity. 
     */ 
     private SystemUiHider mSystemUiHider; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.activity_fullscreen); 

      final View controlsView = findViewById(R.id.fullscreen_content_controls); 
      final View contentView = findViewById(R.id.fullscreen_content); 

      // Set up an instance of SystemUiHider to control the system UI for 
      // this activity. 
      mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS); 
      mSystemUiHider.setup(); 
      mSystemUiHider 
        .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() { 
         // Cached values. 
         int mControlsHeight; 
         int mShortAnimTime; 

         @Override 
         @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) 
         public void onVisibilityChange(boolean visible) { 
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { 
           // If the ViewPropertyAnimator API is available 
           // (Honeycomb MR2 and later), use it to animate the 
           // in-layout UI controls at the bottom of the 
           // screen. 
           if (mControlsHeight == 0) { 
            mControlsHeight = controlsView.getHeight(); 
           } 
           if (mShortAnimTime == 0) { 
            mShortAnimTime = getResources().getInteger(
              android.R.integer.config_shortAnimTime); 
           } 
           controlsView.animate() 
             .translationY(visible ? 0 : mControlsHeight) 
             .setDuration(mShortAnimTime); 
          } else { 
           // If the ViewPropertyAnimator APIs aren't 
           // available, simply show or hide the in-layout UI 
           // controls. 
           controlsView.setVisibility(visible ? View.VISIBLE : View.GONE); 
          } 

          if (visible && AUTO_HIDE) { 
           // Schedule a hide(). 
           delayedHide(AUTO_HIDE_DELAY_MILLIS); 
          } 
         } 
        }); 

      // Set up the user interaction to manually show or hide the system UI. 
      contentView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        if (TOGGLE_ON_CLICK) { 
         mSystemUiHider.toggle(); 
        } else { 
         mSystemUiHider.show(); 
        } 
       } 
      }); 

      // Upon interacting with UI controls, delay any scheduled hide() 
      // operations to prevent the jarring behavior of controls going away 
      // while interacting with the UI. 
      findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener); 
     } 

     @Override 
     protected void onPostCreate(Bundle savedInstanceState) { 
      super.onPostCreate(savedInstanceState); 

      // Trigger the initial hide() shortly after the activity has been 
      // created, to briefly hint to the user that UI controls 
      // are available. 
      delayedHide(100); 
     } 


     /** 
     * Touch listener to use for in-layout UI controls to delay hiding the 
     * system UI. This is to prevent the jarring behavior of controls going away 
     * while interacting with activity UI. 
     */ 
     View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent motionEvent) { 
       if (AUTO_HIDE) { 
        delayedHide(AUTO_HIDE_DELAY_MILLIS); 
       } 
       return false; 
      } 
     }; 

     Handler mHideHandler = new Handler(); 
     Runnable mHideRunnable = new Runnable() { 
      @Override 
      public void run() { 
       mSystemUiHider.hide(); 
      } 
     }; 

     /** 
     * Schedules a call to hide() in [delay] milliseconds, canceling any 
     * previously scheduled calls. 
     */ 
     private void delayedHide(int delayMillis) { 
      mHideHandler.removeCallbacks(mHideRunnable); 
      mHideHandler.postDelayed(mHideRunnable, delayMillis); 
     } 
}