android – 全屏活动向导活动.当我与设备进行互动时,如何停止显示动作栏?

前端之家收集整理的这篇文章主要介绍了android – 全屏活动向导活动.当我与设备进行互动时,如何停止显示动作栏?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用 fullscreen activity wizard创建一个活动时,它会创建一个全屏活动,但是当我点击屏幕上的任何位置时,操作栏显示几秒钟.如何阻止这样做?

FullScreenActivity.java的完整代码

  1. /**
  2. * An example full-screen activity that shows and hides the system UI (i.e.
  3. * status bar and navigation/system bar) with user interaction.
  4. *
  5. * @see systemUIHider
  6. */
  7. public class FullscreenActivity extends Activity {
  8. /**
  9. * Whether or not the system UI should be auto-hidden after
  10. * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
  11. */
  12. private static final boolean AUTO_HIDE = true;
  13.  
  14. /**
  15. * If {@link #AUTO_HIDE} is set,the number of milliseconds to wait after
  16. * user interaction before hiding the system UI.
  17. */
  18. private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
  19.  
  20. /**
  21. * If set,will toggle the system UI visibility upon interaction. Otherwise,* will show the system UI visibility upon interaction.
  22. */
  23. private static final boolean TOGGLE_ON_CLICK = true;
  24.  
  25. /**
  26. * The flags to pass to {@link systemUIHider#getInstance}.
  27. */
  28. private static final int HIDER_FLAGS = systemUIHider.FLAG_HIDE_NAVIGATION;
  29.  
  30. /**
  31. * The instance of the {@link systemUIHider} for this activity.
  32. */
  33. private systemUIHider msystemUIHider;
  34.  
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38.  
  39. setContentView(R.layout.activity_fullscreen);
  40.  
  41. final View controlsView = findViewById(R.id.fullscreen_content_controls);
  42. final View contentView = findViewById(R.id.fullscreen_content);
  43.  
  44. // Set up an instance of systemUIHider to control the system UI for
  45. // this activity.
  46. msystemUIHider = systemUIHider.getInstance(this,contentView,HIDER_FLAGS);
  47. msystemUIHider.setup();
  48. msystemUIHider
  49. .setOnVisibilityChangeListener(new systemUIHider.OnVisibilityChangeListener() {
  50. // Cached values.
  51. int mControlsHeight;
  52. int mShortAnimTime;
  53.  
  54. @Override
  55. @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  56. public void onVisibilityChange(boolean visible) {
  57. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
  58. // If the ViewPropertyAnimator API is available
  59. // (Honeycomb MR2 and later),use it to animate the
  60. // in-layout UI controls at the bottom of the
  61. // screen.
  62. if (mControlsHeight == 0) {
  63. mControlsHeight = controlsView.getHeight();
  64. }
  65. if (mShortAnimTime == 0) {
  66. mShortAnimTime = getResources().getInteger(
  67. android.R.integer.config_shortAnimTime);
  68. }
  69. controlsView
  70. .animate()
  71. .translationY(visible ? 0 : mControlsHeight)
  72. .setDuration(mShortAnimTime);
  73. } else {
  74. // If the ViewPropertyAnimator APIs aren't
  75. // available,simply show or hide the in-layout UI
  76. // controls.
  77. controlsView.setVisibility(visible ? View.VISIBLE
  78. : View.GONE);
  79. }
  80.  
  81. if (visible && AUTO_HIDE) {
  82. // Schedule a hide().
  83. delayedHide(AUTO_HIDE_DELAY_MILLIS);
  84. }
  85. }
  86. });
  87.  
  88. // Set up the user interaction to manually show or hide the system UI.
  89. contentView.setOnClickListener(new View.OnClickListener() {
  90. @Override
  91. public void onClick(View view) {
  92. if (TOGGLE_ON_CLICK) {
  93. msystemUIHider.toggle();
  94. } else {
  95. msystemUIHider.show();
  96. }
  97. }
  98. });
  99.  
  100. // Upon interacting with UI controls,delay any scheduled hide()
  101. // operations to prevent the jarring behavior of controls going away
  102. // while interacting with the UI.
  103. findViewById(R.id.dummy_button).setOnTouchListener(
  104. mDelayHideTouchListener);
  105. }
  106.  
  107. @Override
  108. protected void onPostCreate(Bundle savedInstanceState) {
  109. super.onPostCreate(savedInstanceState);
  110.  
  111. // Trigger the initial hide() shortly after the activity has been
  112. // created,to briefly hint to the user that UI controls
  113. // are available.
  114. delayedHide(100);
  115. }
  116.  
  117. /**
  118. * Touch listener to use for in-layout UI controls to delay hiding the
  119. * system UI. This is to prevent the jarring behavior of controls going away
  120. * while interacting with activity UI.
  121. */
  122. View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
  123. @Override
  124. public boolean onTouch(View view,MotionEvent motionEvent) {
  125. if (AUTO_HIDE) {
  126. delayedHide(AUTO_HIDE_DELAY_MILLIS);
  127. }
  128. return false;
  129. }
  130. };
  131.  
  132. Handler mHideHandler = new Handler();
  133. Runnable mHideRunnable = new Runnable() {
  134. @Override
  135. public void run() {
  136. msystemUIHider.hide();
  137. }
  138. };
  139.  
  140. /**
  141. * Schedules a call to hide() in [delay] milliseconds,canceling any
  142. * prevIoUsly scheduled calls.
  143. */
  144. private void delayedHide(int delayMillis) {
  145. mHideHandler.removeCallbacks(mHideRunnable);
  146. mHideHandler.postDelayed(mHideRunnable,delayMillis);
  147. }
  148. }

解决方法

如果我理解正确,你只想隐藏动作栏?

如果是,请更改此行(将flag_hide_navigation更改为0).

  1. private static final int HIDER_FLAGS = 0;// systemUIHider.FLAG_HIDE_NAVIGATION;

并将其添加到onCreate调用中:

  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3.  
  4. getWindow().requestFeature(Window.FEATURE_ACTION_BAR); //new
  5. getActionBar().hide(); //new
  6. getWindow().setFlags(
  7. WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  8.  
  9. setContentView(R.layout.activity_fullscreen);

之后,如果要显示动作栏,只需从活动中的任意位置调用

  1. getActionBar().show();

猜你在找的Android相关文章