Search code examples
android-layoutandroid-jetpack-compose

Is it possible to disable the Action Bar purely with Jetpack Compose?


In an app that I am working on, I wanted to delete the themes.xml file, since I plan to only use Jetpack Compose's MaterialTheme. I deleted it along with the references to it in AndroidManifest.xml. This seems to have worked fine, except for one thing. There is now an Action Bar visible at the top of my app, like in this example: Image of an Action Bar

It seems that the Action Bar was not there in the first place because of this line in the themes.xml file:

<style name="Theme.Inventory" parent="android:Theme.Material.Light.NoActionBar">

My question is: is it possible to disable the Action Bar without the use of XML?

I tried searching for how I can manipulate this default Action Bar with Jetpack Compose, but was not able to find an answer. I know that you can modify elements such as the Status Bar and the Navigation Bar with a SystemUiController, but I am not aware if that is what I am supposed to use.


Solution

  • In your component activity's onCreate:

    @AndroidEntryPoint
    class MainActivity: ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            // Remove the default action bar
            actionBar?.hide()
            setContent {
                YourAppContent()
            }
        }
    }
    

    This works for me and I have no XML theme.