android点滴12

  在取ActionBar时候总是报nullpointerexception异常,在程序中打印之后也确实是null。在网上找了好多的资料,大家大部分人都认为是SDK版本导致的,也确实有这个原因。版本低于API level 11的SDK是无法使用ActionBar的,只能使用ActionBarSherlock。但是我在Activity中

ActionBar ab = this.getActionBar();
System.out.println("A"+ab);
ab.show();

     打印的结果仍然为null,这是怎么回事呢?查了API后才知道:

     Beginning with Android 3.0 (API level 11), the action bar appears at the top of an activity's window when the activity uses the system's Holo theme (or one of its descendant themes), which is the default. 

    需要设置应用的主题,如在AndroidManifest添加语句

<application android:theme="@android  :style/Theme.Holo">

也就是说取不大ActionBar的愿意有可能你是的SDK版本设置低于15,有可能是没有设置应用的主题。

解决方法:

AndroidManifest中的android:minSdkVersion 或者 android:targetSdkVersion 属性被设置成11或者更高

②为AndroidManifest中的application添加属性

android:theme="@android  :style/Theme.Holo"

转载于:https://my.oschina.net/u/266531/blog/132737

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值