Mobile App/Android

안드로이트 타이틀바/상태바 없애기 (노치 대응)

Jade Choe 2021. 4. 29. 13:07
SMALL

타이틀 바 없애기

경로 : res/values/themes.xml , res/values-night/themes.xml

<style name="Theme.앱이름" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
  ...생략

  <!-- Customize your theme here. -->

  <!--타이틀 바 없애기-->
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>  
</style>

상태 바 없애기

경로 : MainActivity.java

import android.os.Build;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager;

...
public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /* 전체화면 코드 시작 */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
      final WindowInsetsController insetsController = getWindow().getInsetsController();
      if (insetsController != null) {
        insetsController.hide(WindowInsets.Type.statusBars());
      }
    } else {
      getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
      );
    }
    /* 전체화면 코드 끝 */
  }
  ...
}

Before / After

노치 / 펀치홀 대응 (안드로이드 9 이상)

경로 :res/values-v28/themes.xml,res/values-night-v28/themes.xml

<style name="Theme.앱 이름" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
  ... 중략 ...
  <!-- Customize your theme here. -->

  <!--타이틀 바 없애기-->
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>

  <!-- 노치 / 펀치 홀 대응 -->
  <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
  <item name="android:windowTranslucentStatus">true</item>
  <item name="android:windowTranslucentNavigation">true</item>
</style>

최종 결과물

BIG