博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android开发隐藏了actionbar仍然短暂闪现的解决方法
阅读量:7050 次
发布时间:2019-06-28

本文共 1779 字,大约阅读时间需要 5 分钟。

有时候我们在代码里隐藏了actionbar,在打开应用时,仍然短暂闪现下actionbar,用户体验很不好。

 
最简单的方法是 在AndroidManifest.xml中设置主题中配置不显示title或者action,即为:
 
  <style name="NoTitle" parent="android:Theme.Holo.Light">
    <item name="android:windowActionBar">true</item>
    </style>
 
或者
 
 <style name="NoTitle" parent="android:Theme.Holo.Light">
        <item name="android:windowNoTitle">true</item>
    </style>
 
但是有时候,你如果想显示actionbar,就不能在AndroidManifest.xml这么设置,我试过,做上述设置,就不能显示出actionbar了(这个我试的结果是这样,有可以显示的请给我回复),
 
这时,怎么解决这个问题呢,在stackoverflow看到有解决方案,这里贴出来:
 
Setting android:windowActionBar=false truly disables the ActionBar but then, as you say, getActionBar() returns null. This is solved by:
 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();
 
    setContentView(R.layout.splash); // be sure you call this AFTER requestFeature
 
But now there is another problem. After putting windowActionBar=false in the theme, the Activity draws its normal Window Title instead of an ActionBar.
If we try to avoid this by using some of the *.NoTitleBar stock themes or we try to put true in our own theme, it won't work.
The reason is that the ActionBar depends on the Window Title to display itself - that is the ActionBar is a transformed Window Title.
So the trick which can help us out is to add one more thing to our Activity theme xml:
 
 
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
 
This will make the Window Title with zero height, thus practically invisible .
 
In your case, after you are done with displaying the splash screen you can simply call
 
setContentView(R.layout.main);
getActionBar().show()
and you are done. The Activity will start with no ActionBar flickering, nor Window Title showing

转载地址:http://rgsol.baihongyu.com/

你可能感兴趣的文章
Python: The _imagingft C module is not installed错误的解决
查看>>
HTTP请求报文和HTTP响应报文
查看>>
第3课 - 初识程序的灵魂
查看>>
WordPress插件扫描工具plecost
查看>>
【PDF】Java操作PDF之iText超入门
查看>>
PHP:第五章——字符串过滤函数
查看>>
Spring中ApplicationContextAware的用法
查看>>
flask的session解读及flask_login登录过程研究
查看>>
ElasticSearch单机多实例环境部署
查看>>
python 练习
查看>>
Centos 安装 nload
查看>>
python3简单使用requests
查看>>
由一次java作业 引起的思考
查看>>
HDU 3389 Game(博弈)
查看>>
仅IE支持clearAttributes/mergeAttributes方法
查看>>
Linux中U盘和SD卡加载卸载命令
查看>>
github push403错误的处理
查看>>
Hibernate与 MyBatis的比较
查看>>
关于百度地图API的地图坐标转换问题
查看>>
【操作系统】设备管理(五)
查看>>