• 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

    Screenshot from 2013-01-16 12:40:47

    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  

  • 相关阅读:
    基于node.js+socket.io+html5实现的斗地主游戏(1)概述
    [javascript]switchTab:仿腾讯首页Tab栏切换js插件
    [js]利用闭包向post回调函数传参数
    [CSS]利用伪元素实现一些特殊图形 from baidu校招
    [javascript]模块化&命名污染—from 编程精解
    [随手记]2014前端面试题解
    [IE bug] ajax请求 304解决方案
    [java]基于UDP的Socket通信Demo
    [JQuery]ScrollMe滚动特效插件
    java.lang.OutOfMemoryError及解决方案
  • 原文地址:https://www.cnblogs.com/spring87/p/4314037.html
Copyright © 2020-2023  润新知