我正在开发一个使用自定义操作栏布局的应用程序,该布局通过 themes.xml< 中的
。
栏中有一些元素,例如重新加载和一些信息按钮。
在 android:actionBarStyle
和 android:customNavigationLayout
引用android 4
设备上,这些按钮可以通过 findViewById
(在 Activity 中)找到,但在 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>
Activity :
@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 - 在 android 3.2 上的 actionbar 中搜索元素时,findViewById 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21454464/