앱 만들기/안드로이드

안드로이드 탐색 메뉴 숨기기

나도 처음이야 2022. 7. 4.

안드로이드에서 하단에 있는 탐색 메뉴를 지워야 할때가 있다.

탐색 메뉴를 삭제하여 조금 더 큰 화면을 확보하기 위한 UI 일 경우 해당이 된다.

특히, 게임에서는 탐색 메뉴 숨기기가 필요해 보인다.

탐색 메뉴를 없애보자.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        View decorView = getWindow().getDecorView();
        // Hide both the navigation bar and the status bar.
        // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
        // a general rule, you should design your app to hide the status bar whenever you
        // hide the navigation bar.
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        setContentView(R.layout.activity_main);
    }
}

 

위 처럼, 코드를 작성하면 탐색메뉴가 사라진다.

탐색 메뉴는 손가락 스위프를 하단에서 위로 올리면 다시 나타나며, 일정 시간 후 다시 사라진다.

 

안드로이드 에서는 하기 처럼 이야기 한다.

  // Hide both the navigation bar and the status bar.
    // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
    // a general rule, you should design your app to hide the status bar whenever you
    // hide the navigation bar.

탐색바(네이게이션 바)와 상태 바 둘다를 UI 디자인 상 같이 숨기라는 뜻이다.

구글에서 추천하는 UI 디자인이니 따르는 것이 좋을듯 해보인다.

위쪽 상태바는 하기 처럼 한줄의 코드만 추가하면 된다.

getSupportActionBar().hide();

 

개발자 페이지에선,  하기 코드를 추천하는데 null pointer exception 이 발생하였고 필자는 이를 getSupportAcitonBar().hide() 으로 대체 하였다

    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();

즉, 안드로이드 화면을 깨끗하게 싹 지우는 코드는 하기와 같다.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
           View decorView = getWindow().getDecorView();
        // Hide both the navigation bar and the status bar.
        // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
        // a general rule, you should design your app to hide the status bar whenever you
        // hide the navigation bar.
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        getSupportActionBar().hide();

        setContentView(R.layout.activity_main);
    }
}

물론, 안드로이드 API버전 16 이하(4.0) 에서는  하기 코드로 동작을 한다.

    public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // If the Android version is lower than Jellybean, use this call to hide
            // the status bar.
            if (Build.VERSION.SDK_INT < 16) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            setContentView(R.layout.activity_main);
        }
        ...
    }
    

지원 버전에 따라 분기별 작성을 해주면 되겠다.

추가 사항들은 개발자 페이지를 참고하자.

감사합니다. 

전체화면 설정된 모습

 

https://developer.android.com/training/system-ui/status?hl=ko 

 

상태 표시줄 숨기기  |  Android 개발자  |  Android Developers

상태 표시줄 숨기기 이 과정에서는 다른 버전의 Android에서 상태 표시줄을 숨기는 방법에 대해 설명합니다. 상태 표시줄(및 선택적으로 탐색 메뉴)을 숨기면 콘텐츠를 표시하는 데 더 많은 공간

developer.android.com

 

https://developer.android.com/training/system-ui/navigation?hl=ko 

 

탐색 메뉴 숨기기  |  Android 개발자  |  Android Developers

탐색 메뉴 숨기기 이 과정에서는 Android 4.0(API 수준 14)에 도입된 탐색 메뉴를 숨기는 방법에 관해 설명합니다. 이 과정에서는 탐색 메뉴를 숨기는 방법에 중점을 두지만 상태 표시줄 숨기기에 설

developer.android.com

 

 

반응형

댓글