getActionBar 空指针异常

写在前面: http://blog.csdn.net/yueqinglkong/article/details/39577749 这篇文章写的问题点已经很全面,我就直接拿来maker一下,防止以后忘掉.

1. 加载完视图后,再去获取:

写在setContentView()后面。

2.sdk版本:

Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0。

[html]  view plain copy print ?
  1. <uses-sdk  
  2.        android:minSdkVersion="11"  
  3.        android:targetSdkVersion="17" />  
3.配置清单中,添加的主题:

[html]  view plain copy print ?
  1. android:theme="@style/AppTheme" >  
其父主题要具有ActionBar,例如:

[html]  view plain copy print ?
  1. <style name="AppTheme" parent="@android:style/Theme.Holo.Light">  

4.活动类及其父类中,不要设置为全屏:

[html]  view plain copy print ?
  1. //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  

5.没有引用到v11+包中的主题。

values-v11中主题:

[html]  view plain copy print ?
  1. <resources>  
  2.   
  3.     <!--  
  4.         Base application theme for API 11+. This theme completely replaces  
  5.         AppBaseTheme from res/values/styles.xml on API 11+ devices.  
  6.     -->  
  7.     <style name="AppBaseTheme" parent="android:Theme.Holo.Light">  
  8.         <!-- API 11 theme customizations can go here. -->  
  9.     </style>  
  10.   
  11. </resources>  

所以,如果遇到报空的问题,你看看你的工程中有没有values-v11或者v14的包,没有的话就去其他工程中copy一份过来,改下就可以了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值