카테고리 없음

[안드로이드 Kotiln] 풀스크린 & 앱바 보여주기 감추기

훈츠 2020. 6. 2. 12:56
반응형

 

안녕하세요. 훈츠입니다. 금일은 앱을 전체화면, 그리고 앱바를 보여주고 감추는 방법에 관해 포스팅 합니다.

 

풀 스크린 만들기

Window.decorView 에 setSystemUiVisibility(값) 을 입력하면 값에 따란 풀스크린을 만들수도, 해제 할수도 있습니다.

다음 코드를 이용하면 손쉽게 적용이 가능 합니다.

decorView 나 다른 속성에 대한 설명은 다른 블로그의 글을 참조 하길 바랍니다. 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Hoons Blog---https://rain2002kr.tistory.com------------------------------------------------------------------코드///
 
private fun fullScreenMode(switch : Boolean){
        var uiOption = window.decorView.systemUiVisibility
        // 전체화면모드 
        if(switch){
            uiOption =  View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                    View.SYSTEM_UI_FLAG_FULLSCREEN or
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
 
        } else {
            uiOption =  View.SYSTEM_UI_LAYOUT_FLAGS
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        }
        window.decorView.setSystemUiVisibility(uiOption)
}
cs

 

 

풀 스크린이 해제되는 경우

풀스크린 해제되는 경우 방지 하는법

다음과 같이 코드를 적용하더라도, 텍스트 입력과 같이 윈도우 포커스가 달라지면 풀스크린 모드가 해제되는 문제가 발생 합니다.

이 부분을 막기 위해서 다른 방법들도 있지만 다음과 같은 방식을 이용해서 해결 했습니다. 바로 TextWatch 기능에서 afterChanged, beforeChanged 펑션에 위에 만든 함수를 호출하여 풀스크린을 유지하는 방법 입니다. 하지만 어디까지나 정답은 아닌거 같다는 생각이 드네요. 혹시 좀더 편하고 확실한 방법 있으면 알려주세요. ^^

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Hoons Blog---https://rain2002kr.tistory.com------------------------------------------------------------------코드///
 
editText.addTextChangedListener(  object : TextWatcher {
            override fun afterTextChanged(s: Editable?) {
                fullScreenMode(true)
            }
 
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                fullScreenMode(true)
            }
 
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                fullScreenMode(true)
            }
        })
cs

 

앱바 보여주기 , 감추기

앱바 보여주기,감추기는 상당히 쉽습니다. supportActionBar.hide .show 를 이용하면 됩니다.

다음 코드를 참고하세요.

 

1
2
3
4
5
6
7
8
9
//Hoons Blog---https://rain2002kr.tistory.com------------------------------------------------------------------코드///
 
private fun appBarMode(switch : Boolean){
        if(switch){
            supportActionBar?.show()
        }else {
            supportActionBar?.hide()
        }
    }
cs
 

동작 화면

https://youtu.be/QntErh1Vnp4

 

 

코드 공유

 

github.com/rain2002kr/FullScreenMode_AppBarShowHide.git

 

rain2002kr/FullScreenMode_AppBarShowHide

전체화면모드 전환, 앱바 보이기숨기기예제입니다. . Contribute to rain2002kr/FullScreenMode_AppBarShowHide development by creating an account on GitHub.

github.com