find32ById在android 3.2上的操作栏中搜索元素时返回null

我正在开发一个使用自定义操作栏布局的应用程序,该布局通过theme.xml中的 android:actionBarStyle和android:customNavigationLayout引用.
栏中有一些元素,如重载和一些信息按钮.
在android 4设备上,这些按钮可以通过findViewById(在活动内)找到,但在android 3.2上,findViewById返回null.这会抛出NullPointerException.

该应用程序正在使用ActionbarSherlock 4.2.0

这是themes.xml:

<style name="Theme.SRF.Tablet" parent="style/Theme.Sherlock">
     <item name="android:windowContentOverlay">@drawable/header_shadow</item>
     <item name="android:actionBarStyle">@style/TTTActionBar</item> </style>

 <style name="TTTActionBar" parent="style/Widget.Sherlock.ActionBar">
     <item name="android:background">@drawable/bg_header</item>
     <item name="android:customNavigationLayout">@layout/actionbar_custom</item>
 </style>

活动:

@Override
    protected void onCreate(Bundle _savedInstanceState) {
        setContentView(...);
        // next line throws NullPointerException on android 3.2
        findViewById(R.id.actionbar_custom_bt_refresh).setonClickListener(mClickListener);
        ....
    }

解决方法

我不知道这对你有帮助,但是从 here开始:

尝试添加

<item name="customNavigationLayout">@layout/custom_action</item>

同意:

<item name="android:customNavigationLayout">@layout/custom_action</item>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...