简体   繁体   中英

Android - Hiding action bar in material theme in xml

I'm using a theme that inherits from "android:Theme.Material.Light" and am unable to find a way to hide the action bar from the xml style customizations. When using "Theme.AppCompat.Light" I was able to do it with something like this

<style name="MyTheme" parent="Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

How can I achieve a similar result with the material theme? I know you can hide it programmatically but not only is it inconvenient because you can't actually see the real layout on Android studio without having to run the app every time, but also, the action bar still appears for a second when you run the app, before getActionBar().hide() is run and it looks really unprofessional.

SOLUTION:

<style name="MyTheme" parent="android:Theme.Material.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
</style>
 <style name="NoActionBar" parent="_AppTheme">
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>

and then apply the style to the Activity in your manifest as follow :

<activity
            android:name=".youractivity"
            android:theme="@style/NoActionBar" > 

then if your java class extends the ActionBarActvity fix it to extend the Activity and also you had to change all the other Acivity to extend the Activity Class not the ActionBarActivity :)

i hope this will help you :)

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

Well I'm a bit late, but if someone is interested here is my solution.

I needed to inherit from a theme which has the action bar visible, so not using theme.NoActionBar.

Looking into the system theme here's what I found:

<style name="MainTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM