博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
getActionBar()空指针异常
阅读量:6271 次
发布时间:2019-06-22

本文共 1503 字,大约阅读时间需要 5 分钟。

网上的各种解决方案已经不少了,但是不适合于我的,谷歌一种新的解决方案

  

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 

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.  

转载地址:http://movpa.baihongyu.com/

你可能感兴趣的文章
[Javascript] Immute Object
查看>>
Java 关于finally、static
查看>>
Posix mq和SystemV mq区别
查看>>
P6 EPPM Manual Installation Guide (Oracle Database)
查看>>
XMPP协议、IM、客户端互联详解
查看>>
PHP写文件函数
查看>>
mysql的sql_mode合理设置
查看>>
函数连续性与可导性
查看>>
linux下libevent安装
查看>>
用ip来获得用户所在地区信息
查看>>
卡尔曼滤波
查看>>
linux下面覆盖文件,如何实现直接覆盖,不提示
查看>>
CSS3阴影 box-shadow的使用和技巧总结
查看>>
Linux下高cpu解决方案
查看>>
SQL事务用法begin tran,commit tran和rollback tran的用法
查看>>
centos7 crontab笔记
查看>>
.Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");
查看>>
【Unity3D基础教程】给初学者看的Unity教程(零):如何学习Unity3D
查看>>
Android Mina框架的学习笔记
查看>>
合并两个排序的链表
查看>>