有时候我们在代码里隐藏了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. 杭电ACM 素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. [LeetCode]题解(python):058-Length of Last Word

    题目来源: https://leetcode.com/problems/length-of-last-word/ 题意分析: 给出只包括大小写和空格的字符,输出最后一个单词的长度. 题目思路: 从最后 ...

  3. C语言之辗转相除法

    最大公约数和最小公倍数 从键盘输入两个正整数,求出其最大公约数和最小公倍数.代码如下: #include<stdio.h>int ss(int);int main(void){ int a ...

  4. Week14(12月9日)

    Part I:提问 =========================== 1.ASP.NET MVC围绕事件驱动的页面声明周期而建立,在渲染的页面上可以触发事件. 2.ASP.NET MVC脱离了H ...

  5. 挺有意思的HBase日志+Splunk

    如题,转载自: http://hi.baidu.com/harry_lime/item/10cf2c174853c7ea39cb3042 如何模拟拔盘操作 Linux has a nifty way ...

  6. codeblocks + MinGW 以及vc 使用预编译头文件的方法

    MinGW编译器: 1.打开工程文件,在工程文件浏览其中,在你要设置为预编译的头文件上,点击鼠标右键,选择“属性(properties)”  你会看到一个多页面的属性框,选择“构建(build)”页面 ...

  7. cocos2d-x 通过JNI实现c/c++和Android的java层函数互调

    文章摘要: 本文主要实现两个功能: (1)通过Android sdk的API得到应用程序的包名(PackageName),然后传递给c++层函数. (2)通过c++函数调用Android的java层函 ...

  8. setuptools,easy_install使用

    当需要安装第三方python包时,可能会用到easy_install命令.easy_install是由PEAK(Python Enterprise Application Kit)开发的setupto ...

  9. 基于visual Studio2013解决C语言竞赛题之0404循环求和

      题目 解决代码及点评 这道题考验for循环和一个简单的算法 因为每次累加的值有规律,后面一次累加是前面一次累加的两倍 所以可以用简单的循环,计算累加项和累加结果 /************ ...

  10. Redhat 5.8系统安装R语言作Arima模型预测

    请见Github博客:http://wuxichen.github.io/Myblog/timeseries/2014/09/02/RJavaonLinux.html