如何使android的全屏幕活动总是可见的操作栏 [英] How to make action bar in android full screen activity always visible

查看:127
本文介绍了如何使android的全屏幕活动总是可见的操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个应用程序在那里我有一个全屏幕的活动。在全屏活动的操作栏是自动隐藏默认情况下。我想使操作栏始终可见。 我试图切换就像AUTO_HIDE等变量,但它是没有用的。

 包com.bhargav.profiletimer;

进口com.bhargav.profiletimer.util.SystemUiHider;

进口android.annotation.TargetApi;
进口android.app.Activity;
进口android.content.Intent;
进口android.os.Build;
进口android.os.Bundle;
进口android.os.Handler;
进口android.view.MotionEvent;
进口android.view.View;


/ **
 *一个例子全屏的活动,显示和隐藏系统UI(即
 *状态栏和导航/系统吧)与用户交互。
 *
 * @see SystemUiHider
 * /
公共类TimersList延伸活动{
/ **
 *所述系统UI是否应该自动隐藏后
 * {@link #AUTO_HIDE_DELAY_MILLIS}毫秒。
 * /
私有静态最终布尔AUTO_HIDE = TRUE;

/ **
 *如果{@link #AUTO_HIDE}设置,毫秒数后,要等待
 *用户隐藏的系统UI之前的交互。
 * /
私有静态最终诠释AUTO_HIDE_DELAY_MILLIS = 3000;

/ **
 *如果设置,将切换时的交互系统用户界面的可视性。除此以外,
 *将显示在交互系统用户界面的可视性。
 * /
私有静态最终布尔TOGGLE_ON_CLICK = TRUE;

/ **
 *这些标志传递给{@link SystemUiHider#的getInstance}。
 * /
私有静态最终诠释HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

/ **
 *在{@link SystemUiHider}这项活动的实例。
 * /
私人SystemUiHider mSystemUiHider;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

    的setContentView(R.layout.activity_timers_list);

    最后查看controlsView = findViewById(R.id.fullscreen_content_controls);
    最后查看内容查看= findViewById(R.id.fullscreen_content);

    //设置SystemUiHider的一个实例来控制系统的用户界面
    //这个活动。
    mSystemUiHider = SystemUiHider.getInstance(本,内容查看,HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider
            .setOnVisibilityChangeListener(新SystemUiHider.OnVisibilityChangeListener(){
                //缓存值。
                INT mControlsHeight;
                INT mShortAnimTime;

                @覆盖
                @TargetApi(Build.VERSION_ codeS.HONEYCOMB_MR2)
                公共无效onVisibilityChange(布尔可见){
                    如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.HONEYCOMB_MR2){
                        //如果ViewPropertyAnimator API可用
                        //(蜂窝MR2及更高版本),用它来动画
                        //在布局时的底部UI控件
                        // 屏幕。
                        如果(mControlsHeight == 0){
                            mControlsHeight = controlsView.getHeight();
                        }
                        如果(mShortAnimTime == 0){
                            mShortAnimTime = getResources()。getInteger(
                                    android.R.integer.config_shortAnimTime);
                        }
                        controlsView.animate()
                                .translationY(可见0:mControlsHeight)
                                .setDuration(mShortAnimTime);
                    } 其他 {
                        //如果ViewPropertyAnimator API并不
                        //可用,只是显示或隐藏在布局UI
                        //控制。
                        controlsView.setVisibility(?可见View.VISIBLE:View.GONE);
                    }

                    如果(可见的放大器;&安培; AUTO_HIDE){
                        //安排一个隐藏()。
                        delayedHide(AUTO_HIDE_DELAY_MILLIS);
                    }
                }
            });

    //设置用户交互手动显示或隐藏的系统UI。
    contentView.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图查看){
            如果(TOGGLE_ON_CLICK){
                mSystemUiHider.toggle();
            } 其他 {
                mSystemUiHider.show();
            }
        }
    });

    //在与UI控件交互,拖延任何计划隐藏()
    //的控制操作,以prevent的不和谐行为消失
    //而与UI交互。
    findViewById(R.id.button1).setOnTouchListener(mDelayHideTouchListener);
}

@覆盖
保护无效onPostCreate(包savedInstanceState){
    super.onPostCreate(savedInstanceState);

    //触发初始隐藏()后不久,该活动已
    //创建,简单地提示到UI控件的用户
    //可用。
    delayedHide(100);
}


/ **
 *触摸监听器,以用于布局UI控件延迟隐藏
 *系统UI。这是prevent控件消失的不和谐行为
 *同时与活动UI交互。
 * /
View.OnTouchListener mDelayHideTouchListener =新View.OnTouchListener(){
    @覆盖
    公共布尔onTouch(查看视图,MotionEvent motionEvent){
        如果(AUTO_HIDE){
            delayedHide(AUTO_HIDE_DELAY_MILLIS);
        }
        返回false;
    }
};

处理器mHideHandler =新的处理程序();
可运行mHideRunnable =新的Runnable(){
    @覆盖
    公共无效的run(){
        mSystemUiHider.hide();
    }
};

/ **
 *附表调用隐藏()在[延迟]毫秒,取消所有
 * previously预定电话。
 * /
私人无效delayedHide(INT delayMillis){
    mHideHandler.removeCallbacks(mHideRunnable);
    mHideHandler.postDelayed(mHideRunnable,delayMillis);
}

公共无效startAddWizard(查看视图)
{
    意向意图=新的意图(这一点,AddWizard.class);
    startActivity(意向);
}
}
 

解决方案

您code:

 私有静态最终诠释HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
 

你所需要的:

 私有静态最终诠释HIDER_FLAGS = SystemUiHider.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES;
 

问题解决了。

I am making an app where I have a full screen activity. The action bar in full screen activity is auto hiding by default. I want to make the action bar always visible. I tried toggling the variables like AUTO_HIDE, etc. but it was of no use.

package com.bhargav.profiletimer;

import com.bhargav.profiletimer.util.SystemUiHider;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;


/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 *
 * @see SystemUiHider
 */
public class TimersList 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_timers_list);

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

public void startAddWizard(View view)
{
    Intent intent = new Intent(this, AddWizard.class);
    startActivity(intent);
}
}

解决方案

your code:

private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

what you need:

private static final int HIDER_FLAGS = SystemUiHider.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES;

problem solved.

这篇关于如何使android的全屏幕活动总是可见的操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆