【Android】去掉titlebar的最優解決方案

今日在作項目時出現了gralloc out of memory的錯誤,通過幾日的測試調整,最終肯定是在AndroidManifest.xml中使用了android:theme="@android:style/Theme.Translucent.NoTitleBar" 的配置項致使的,因此在隱藏titlebar時,不建議使用該方法。java

通過試驗,使用一下方式能夠達到一樣效果,且不會出現oom的錯誤。android

在onCreate方法中調用:app

requestWindowFeature(Window.FEATURE_NO_TITLE);

而後再在style.xml中配置:測試

<style name="Theme.MyTheme" parent="android:style/Theme.Translucent">
    <item name="android:windowContentOverlay">@null</item>
</style>

 最後在AndroidManifest.xml的application配置:code

<application android:icon="@drawable/n_icon" android:label="@string/app_name" android:theme="@style/Theme.MyTheme">
通過以上設置,可避免oom錯誤,同時實現隱藏titlebar的效果。
相關文章
相關標籤/搜索