android点滴12

  在取ActionBar时候老是报nullpointerexception异常,在程序中打印以后也确实是null。在网上找了好多的资料,你们大部分人都认为是SDK版本致使的,也确实有这个缘由。版本低于API level 11的SDK是没法使用ActionBar的,只能使用ActionBarSherlock。可是我在Activity中 html

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.  java

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

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

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

解决方法: this

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

②为AndroidManifest中的application添加属性 .net

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

相关文章
相关标签/搜索