android去掉titlebar的最优解决方案

来源:互联网 发布:cos碧瑶知乎 编辑:程序博客网 时间:2024/05/16 10:51

今日在做项目时出现了gralloc out of memory的错误,经过几日的测试调整,最终确定是在AndroidManifest.xml中使用了android:theme="@android:style/Theme.Translucent.NoTitleBar" 的配置项导致的,所以在隐藏titlebar时,不建议使用该方法。

经过试验,使用一下方式可以达到同样效果,且不会出现oom的错误。

在onCreate方法中调用:

1requestWindowFeature(Window.FEATURE_NO_TITLE);

然后再在style.xml中配置:

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

 最后在AndroidManifest.xml的application配置:

1<application android:icon="@drawable/n_icon" android:label="@string/app_name" android:theme="@style/Theme.MyTheme">

经过以上设置,可避免oom错误,同时实现隐藏titlebar的效果。
原创粉丝点击