Android 활동에서 탐색 모음을 영구적으로 숨기는 방법은 무엇입니까?
내 활동에서 내비게이션 바를 영구적으로 숨기고 싶습니다 (전체 시스템 UI가 아님). 이제이 코드를 사용하고 있습니다.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
막대를 숨기지 만 사용자가 화면을 터치하면 다시 표시됩니다. 활동할 때까지 영구적으로 숨길 수있는 방법이 있습니까 onStop()?
짧은 발췌:
HideNavigationBarComponent.java
Android 4.4 이상용입니다.
몰입 형 모드 https://developer.android.com/training/system-ui/immersive.html 사용해보기
빠른 스 니펫 ( 활동 클래스 용) :
private int currentApiVersion;
@Override
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
currentApiVersion = android.os.Build.VERSION.SDK_INT;
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
// This work only for android 4.4+
if(currentApiVersion >= Build.VERSION_CODES.KITKAT)
{
getWindow().getDecorView().setSystemUiVisibility(flags);
// Code below is to handle presses of Volume up or Volume down.
// Without this, after pressing volume buttons, the navigation bar will
// show up and won't hide
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
decorView.setSystemUiVisibility(flags);
}
}
});
}
}
@SuppressLint("NewApi")
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
if(currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
{
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
볼륨 크게 또는 볼륨 작게를 누를 때 문제가있는 경우 탐색 모음에 표시됩니다. 나는에 코드를 추가 onCreate참조 setOnSystemUiVisibilityChangeListener
다음은 또 다른 관련 질문입니다.
몰입 형 모드 탐색은 볼륨을 누르거나 복원을 최소화 한 후 고정됩니다.
이 작업을 수행.
public void FullScreencall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
}
이것은 100 % 작동하며 더 낮은 API 버전에서도 똑같이 할 수 있습니다. 비록 답변이 늦더라도 다른 사람에게 도움이되기를 바랍니다.
이것을 영구적으로 유지하려면 메서드 FullscreenCall()내부를 호출 하십시오 onResume().
사용하다:-
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Android 4 이상을 실행하는 태블릿에서는 시스템 / 내비게이션 바를 숨길 수 없습니다.
에서 문서 :
SYSTEM_UI_FLAG_HIDE_NAVIGATION은 탐색 모음을 완전히 숨기도록 요청하는 새 플래그입니다. 이 기능은 일부 핸드셋에서 사용하는 탐색 모음에서만 작동합니다 (태블릿에서 시스템 표시 줄을 숨기지 않음).
Android 개발자 사이트 에 따르면
(내가 아는 한) 내비게이션 바를 영구적으로 숨길 수 없다고 생각합니다 ..
그러나 한 가지 트릭을 할 수 있습니다. 그 속임수는 당신을 생각합니다.
Just when the navigation bar shows up when user touches the screen. Immediately hide it again. Its fun.
Check this.
void setNavVisibility(boolean visible) {
int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| SYSTEM_UI_FLAG_LAYOUT_STABLE;
if (!visible) {
newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
| SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
// If we are now visible, schedule a timer for us to go invisible.
if (visible) {
Handler h = getHandler();
if (h != null) {
h.removeCallbacks(mNavHider);
if (!mMenusOpen && !mPaused) {
// If the menus are open or play is paused, we will not auto-hide.
h.postDelayed(mNavHider, 1500);
}
}
}
// Set the new desired visibility.
setSystemUiVisibility(newVis);
mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE);
mPlayButton.setVisibility(visible ? VISIBLE : INVISIBLE);
mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE);
}
See this for more information on this ..
I think the blow code will help you, and add those code before setContentView()
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
Add those code behind setContentView() getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
It's my solution:
First, define boolean that indicate if navigation bar is visible or not.
boolean navigationBarVisibility = true //because it's visible when activity is created
Second create method that hide navigation bar.
private void setNavigationBarVisibility(boolean visibility){
if(visibility){
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
navigationBarVisibility = false;
}
else
navigationBarVisibility = true;
}
By default, if you click to activity after hide navigation bar, navigation bar will be visible. So we got it's state if it visible we will hide it.
Now set OnClickListener to your view. I use a surfaceview so for me:
playerSurface.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setNavigationBarVisibility(navigationBarVisibility);
}
});
Also, we must call this method when activity is launched. Because we want hide it at the beginning.
setNavigationBarVisibility(navigationBarVisibility);
Its a security issue: https://stackoverflow.com/a/12605313/1303691
therefore its not possible to hide the Navigation on a tablet permanently with one single call at the beginning of the view creation. It will be hidden, but it will pop up when touching the Screen. So just the second touch to your screen can cause a onClickEvent on your layout. Therefore you need to intercept this call, but i haven't managed it yet, i will update my answer when i found it out. Or do you now the answer already?
Try this:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
For people looking at a simpler solution, I think you can just have this one line of code in onStart()
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
It's called Immersive mode. You may look at the official documentation for other possibilities.
'IT TIP' 카테고리의 다른 글
| Java에서 main 메소드를 오버로드 할 수 있습니까? (0) | 2020.11.19 |
|---|---|
| 정확한 시간에 실행되도록 크론 작업을 설정하는 방법은 무엇입니까? (0) | 2020.11.19 |
| Apple Mach-O 링커 경고 "옵션에 대한 디렉토리를 찾을 수 없음…" (0) | 2020.11.19 |
| Webpack 가져 오기는 가져 오기 순서에 따라 정의되지 않은 것을 반환합니다. (0) | 2020.11.19 |
| RSA를 통해 고유 한 공개 및 개인 키를 생성하는 방법 (0) | 2020.11.19 |