getActionBar()空指针异常
网上的各种解决方案已经不少了,但是不适合于我的,谷歌一种新的解决方案
you can directly specify it in manifest file
|
1
2
3
4
|
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > |
There are 3 themes available Theme.Holo.Light/Theme.Holo.Dark/Theme.Holo.Light.DarkActionBar.
Theme.Holo.Light requires API level >=11 while Theme.Holo.Dark/Theme.Holo.Light.DarkActionBar requires API level >= 14
If you want to change themes according to API level, you can specify a base appTheme, and override it in style files

|
1
2
3
4
|
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@style/appTheme" > |
values/styles.xml
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<resources> <!-- Base application theme, dependent on API level. --> <style name="AppBaseTheme" parent="android:Theme.Light"> </style> <style name="AppTheme" parent="AppBaseTheme"> </style></resources> |
values-v14/styles.xml
|
1
2
3
4
5
6
7
8
9
10
11
|
<resources> <!-- Base application theme for API 14+. This theme completely replaces AppBaseTheme --> <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> </style></resources> |
If you want a consistent theme while maintain compatibility with lower API levels, look at what these people are doing op
The second solution is to request ActionBar feature manually instead making the theme do it for you. I am too lazy to try it myself. This link explain it pretty well. op
getActionBar()空指针异常的更多相关文章
- Android getActionBar()报空指针异常
1. 加载完视图后,再去获取: 写在setContentView()后面. 2.sdk版本: Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0. <uses- ...
- getActionBar()为null的解决方法总结(引用他人)
最近在看android actionBar的使用,环境为AndroidStudio,建一个简单的工程,功能为:两个按钮,一个单击用于显示actionbar,一个用于隐藏actionbar.默认acti ...
- 【Android】getActionBar()为null的解决方法总结
前言 在使用 ActionBar的时候,有时候会爆出空指针异常,这是由于应用没有获取到 ActionBar 导致的,而导致应用没有获取到 ActionBar 的原因比較多.所以我们以下就来总结一下 A ...
- FragmentPagerAdapter加载fragment并使用setUserVisibleHint()处理预加载时遇到的坑,给textview赋值时出现的空指针异常
FragmentPagerAdapter加载fragment并使用setUserVisibleHint()处理预加载时,给textview赋值时出现的空指针异常 public class BaseFr ...
- java空指针异常:java.lang.NullPointException
一.什么是java空指针异常 我们都知道java是没有指针的,这里说的"java指针"指的就是java的引用,我们不在这里讨论叫指针究竟合不合适,而只是针对这个异常本身进行分析.空 ...
- ListView.setAdapter(adapter);空指针异常的解决的总结
报空指针异常一般的情况: 1,没有找到布局文件的ID 检验是不是id重复或者写错了 2.控件没有实例化 3.没有找到布局文件的id,要看看是不是加载了布局了,必须加载了对应的布局才能找到对应布局下的 ...
- 没有R.java问题找不到getActionBar()方法
android项目,可是项目中没有重要的R.java,并且报错,说是找不到getActionBar()方法,上网寻找原因,终于寻得解决方法: 1.解决项目中没有R.java问题.在Eclipse ...
- Myeclipse下JSP打开报空指针异常解决方法。
Myeclipse下JSP打开报空指针异常解决方法 一.运行JSP文件就出错 静态的JSP页面访问时候正常,只要是牵涉到数据库的页面就出错,出错见下图. 出现这种情况让我调试了一天,各种断点,各种改代 ...
- java空指针异常 for循环时,使用了值为null的变量
错误代码: for(Map<String,Object> videoItemMap:learnVideoList){ String videoStuId=MapUtils.getStrin ...
随机推荐
- ThreadPoolExecutor(转)
让ThreadPoolExecutor的workQueue占满时自动阻塞submit()方法 By learnhard | 2015 年 09 月 04 日 0 Comment 转载请注明出处:htt ...
- WebConfig
花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...
- 【SSH进阶之路】Hibernate基本原理(一)
在开始学Hibernate之前,一直就有人说:Hibernate并不难,无非是对JDBC进一步封装.一句不难,难道是真的不难还是眼高手低? 如果只是停留在使用的层面上,我相信什么技术都不难,看看别人怎 ...
- Shell学习之Shift的用法
位置参数可以用shift命令左移.比如shift 3表示原来的$4现在变成$1,原来的$5现在变成$2等等,原来的$1.$2.$3丢弃,$0不移动.不带参数的shift命令相当于shift 1 ...
- php number_format()保留小数点后几位有效数的函数 千位分组来格式化数字(转)
PHP保留小数点后2位的函数number_format number_format(带小数点的书,小数点后保留的位数) number_format(8.3486,2); //取得小数点后2位有效数/ ...
- FPGA的LE数与门数的关系(转)
一般而言FPGA等效门数的计算方法有两种 一是把FPGA基本单元(如LUT+FF,ESB/BRAM)和实现相同功能的标准门阵列比较,门阵列中包含的门数即为该FPGA基本单元的等效门数,然后乘以基本单元 ...
- Android实现ListView或GridView首行/尾行距离屏幕边缘距离
直接上关键属性: 设置ListView或GridView的android:clipToPadding = true, 然后通过paddingTop和paddingBottom设置距离就好了.
- 跨域(cross-domain)访问 cookie (读取和设置)
Passport 一方面意味着用一个帐号可以在不同服务里登录,另一方面就是在一个服务里面登录后可以无障碍的漫游到其他服务里面去.坦白说,目前 sohu passport 在这一点实现的很烂(不过俺的工 ...
- 2015第6周三ztree的使用
今天第一次真正在开发中使用了ztree组件,在实践过程体会了从生到熟的乐趣,从开始看不太懂ztree的api到后面熟悉理解其API布局,学习其中的各demo,感觉很不错,简单记录下使用ztree的经验 ...
- [Leetcode][Python]46: Permutations
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...