Android [ Java, Kotlin ]
안드로이드 프로그래밍 - 타이틀바(Action bar) 제거 방안
Moonsu99
2023. 10. 15. 22:15
환경
- OS - Mac OS 13.5.2
- Tools - Android Studio Iguana | 2023.2.1 Canary 5
- Language - Kotlin
- android version - 12
- tartgetSDK - 33
- minSDK - 28
요약
안드로이드 스튜디오에서 앱 개발 시 상단에 존재하는 타이틀바를 제거하는 경우가 많다.
이 문제를 해결하기 위해 타이틀바를 제거하는 방법을 2가지 제공하겠다.
해결방안
1. Themes.xml수정
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Applyserviceandroid" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
</resources>
parent에 NoActionbar을 지원하는 테마를 적용시키는 것을 사용하거나,
style속성에 다음 두 속성을 넣으면 ActionBar를 제거할 수 있다.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
2. 코드로 구현
하지만 테마를 앞서 말한듯이 작성하면 앱 전체에 영향이 미친다. (모든 Activity에 ActionBar가 사라지는 현상)
따라서 Kotlin 이나 Java코드로 구현하는 방법도 알고 있어야 한다.
Kotlin
supportActionBar?.hide()
Java
getSupportActionBar().hide();