有时候我们在代码里隐藏了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

android开发隐藏了actionbar仍然短暂闪现的解决方法的更多相关文章

  1. Android开发调试无法连接到夜神模拟器的解决方法

    Android开发调试无法连接到夜神模拟器的解决方法: 一般原因是adb的版本不一致造成的!!!!!换成一样的就可以了. 在网上看到的方法,特记录下来: 1.任务管理器里看下,adb.exe以及nox ...

  2. Android开发中常见的内存泄露案例以及解决方法总结

    1.单例模式引起的内存泄露 由于单例模式的静态特性,使得它的生命周期和我们的应用一样长,如果让单例无限制的持有Activity的强引用就会导致内存泄漏如错误代码示例: public class Use ...

  3. Android开发之华为手机无法看log日志解决方法(亲测可用华为荣耀6)

    作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985, 转载请说明出处. 在上家公司上班的时候,公司配了华为荣耀6的测试机,发现在eclipse下 无法查看 ...

  4. Android开发中,那些让您觉得相见恨晚的方法、类或接口

    Android开发中,那些让你觉得相见恨晚的方法.类或接口本篇文章内容提取自知乎Android开发中,有哪些让你觉得相见恨晚的方法.类或接口?,其实有一部是JAVA的,但是在android开发中也算常 ...

  5. Android开发常见的Activity中内存泄漏及解决办法

    上一篇文章楼主提到由Context引发的内存泄漏,在这一篇文章里,我们来谈谈Android开发中常见的Activity内存泄漏及解决办法.本文将会以“为什么”“怎么解决”的方式来介绍这几种内存泄漏. ...

  6. Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全

    原文:Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全 前面简单学习了一些Android UI的一些基础知识,那么接下来我们一起来详细学习Android的 ...

  7. PHP开发中常见的安全问题详解和解决方法(如Sql注入、CSRF、Xss、CC等

    页面导航: 首页 → 网络编程 → PHP编程 → php技巧 → 正文内容 PHP安全 PHP开发中常见的安全问题详解和解决方法(如Sql注入.CSRF.Xss.CC等) 作者: 字体:[增加 减小 ...

  8. 启动android程序和虚拟机时候出现如下错误的解决方法

    启动android程序和虚拟机时候出现如下错误的解决方法. 错误重现: [2011-07-13 16:22:48 - Emulator] invalid command-line parameter: ...

  9. HBuilder开发iPad程序不能全屏显示的解决方法

    HBuilder开发iPad程序不能全屏显示的解决方法: targets选择HBuilder=>Deployment Info=> devices选择Universal即可

随机推荐

  1. HTML5 总结-地理定位-6

    HTML5 地理定位 定位用户的位置 HTML5 Geolocation API 用于获得用户的地理位置. 鉴于该特性可能侵犯用户的隐私,除非用户同意,否则用户位置信息是不可用的. 浏览器支持 Int ...

  2. 查找最小的k个元素

    题目:输入n个整数,输出其中最小的k个. 例如输入1,2,3,4,5,6,7和8这8个数字,则最小的4个数字为1,2,3和4. 两种思路,无非就是时间与空间的妥协. 限制空间的时候要对原数组进行排序, ...

  3. app添加辅助功能时,需要注意的测试点

    最近项目里需要在辅助功能添加对应的服务,来支持对应的功能实现: 1.对用户添加app进行信息管理功能中,该app有对应的通知或信息时在app的logo上显示提示标志. 2.用户下载一款app后能够自动 ...

  4. SiteMesh

    1.导入对SiteMesh.jar的依赖 <dependency>      <groupId>org.sitemesh</groupId>      <ar ...

  5. JAVA中IO和异常处理练习

    1.SystemI\O练习:1)通过键盘输入若干字符,并通过显示器输出:2)定义一个静态方法validOrNot()用于对输入的字符进行合法性校验,若包含非英文字符,则抛出IllegalStringE ...

  6. Swift 自定义炫酷下拉刷新效果

    先来看下效果 下拉刷新 其实下拉刷新没大家想得那么难.本文已第二个为例子.给大家讲解下下拉刷新的做法(完整代码后面会放上) 首先,先搞一个single View Application .然后进Mai ...

  7. Android:源码环境下移植第三方的apk内置到ROM(System Image)中

    1. 首先在vendor目录下新建一个the3rdapk的目录,将需要内置的apk丢进去,目录名自己随意定. 2. 在 build/target/product/common.mk最后面,在$(cal ...

  8. STL之stack

    一.stack(栈) 栈:LIFO 后进先出: 首先要指出的是,stack并非和STL的其他类模板是独立的容器,stack是自适应容器(容器适配器) stack<int, deque<in ...

  9. 简单仿京东导航下拉菜单 javascript

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  10. golang channel初次接触

    goroutine之间的同步 goroutine是golang中在语言级别实现的轻量级线程,仅仅利用go就能立刻起一个新线程.多线程会引入线程之间的同步问题,经典的同步问题如生产者-消费者问题,在c, ...