【问题标题】:How can Hide status bar如何隐藏状态栏
【发布时间】:2016-03-19 06:51:52
【问题描述】:

我被状态栏隐藏所困。让我解释一下我正在实施活动并将清单文件放在android:windowSoftInputMode="adjustResize" 中,以便在edittext, 下面的键盘位置工作正常,但我也想隐藏navigation bar,所以我使用"Theme.Holo.Light.NoActionBar.Fullscreen" 主题。但是当键盘出现应用导航栏时也会滚动。键盘出现时如何限制滚动导航栏并隐藏通知栏。

【问题讨论】:

标签: android android-manifest


【解决方案1】:

我认为这对你有帮助 => http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)

=>setSystemUiVisibility(newVis); //这个方法对你有帮助

=> 这是用于提供信息和更好理解的类。

public 静态类 Content 扩展 ScrollView 实现 View.OnSystemUiVisibilityChangeListener, View.OnClickListener { TextView mText; 文本视图 mTitleView; SeekBar mSeekView; 布尔 mNavVisible; int mBaseSystemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_STABLE; int mLastSystemUiVis;

Runnable mNavHider = new Runnable() {
    @Override public void run() {
        setNavVisibility(false);
    }
};

public Content(Context context, AttributeSet attrs) {
    super(context, attrs);

    mText = new TextView(context);
    mText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    mText.setText(context.getString(R.string.alert_dialog_two_buttons2ultra_msg));
    mText.setClickable(false);
    mText.setOnClickListener(this);
    mText.setTextIsSelectable(true);
    addView(mText, new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    setOnSystemUiVisibilityChangeListener(this);
}

public void init(TextView title, SeekBar seek) {
    // This called by the containing activity to supply the surrounding
    // state of the content browser that it will interact with.
    mTitleView = title;
    mSeekView = seek;
    setNavVisibility(true);
}

@Override public void onSystemUiVisibilityChange(int visibility) {
    // Detect when we go out of low-profile mode, to also go out
    // of full screen.  We only do this when the low profile mode
    // is changing from its last state, and turning off.
    int diff = mLastSystemUiVis ^ visibility;
    mLastSystemUiVis = visibility;
    if ((diff&SYSTEM_UI_FLAG_LOW_PROFILE) != 0
            && (visibility&SYSTEM_UI_FLAG_LOW_PROFILE) == 0) {
        setNavVisibility(true);
    }
}

@Override protected void onWindowVisibilityChanged(int visibility) {
    super.onWindowVisibilityChanged(visibility);

    // When we become visible, we show our navigation elements briefly
    // before hiding them.
    setNavVisibility(true);
    getHandler().postDelayed(mNavHider, 2000);
}

@Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);

    // When the user scrolls, we hide navigation elements.
    setNavVisibility(false);
}

@Override public void onClick(View v) {
    // When the user clicks, we toggle the visibility of navigation elements.
    int curVis = getSystemUiVisibility();
    setNavVisibility((curVis&SYSTEM_UI_FLAG_LOW_PROFILE) != 0);
}

void setBaseSystemUiVisibility(int visibility) {
    mBaseSystemUiVisibility = visibility;
}

void setNavVisibility(boolean visible) {
    int newVis = mBaseSystemUiVisibility;
    if (!visible) {
        newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN;
    }
    final boolean changed = newVis == getSystemUiVisibility();

    // Unschedule any pending event to hide navigation if we are
    // changing the visibility, or making the UI visible.
    if (changed || visible) {
        Handler h = getHandler();
        if (h != null) {
            h.removeCallbacks(mNavHider);
        }
    }

    // Set the new desired visibility.
    setSystemUiVisibility(newVis);
    mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE);
    mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE);
}

}

【讨论】:

    猜你喜欢
    • 2016-02-15
    • 1970-01-01
    • 2015-09-17
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    相关资源
    最近更新 更多