我正在开发 Android 项目,目标版本是 4.2.2,但最低支持版本是 2.3。该项目大量使用 ActionBarSherlock 库。在 list 文件中我写道:
android:theme="@style/Theme.Sherlock" >
当我在 Android 4.2.2 设备和 Android 4.0 上测试我的项目时,一切工作正常,但当我尝试在 Android 2.3 上运行该应用程序时,它崩溃并显示以下日志:
在调试过程中,我注意到自定义 ActionBar (custom_bar) 上的一些按钮为空。我使用此代码来创建自定义 ActionBar:
ActionBar theBar = getSupportActionBar();
theBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
theBar.setCustomView(R.layout.custom_bar);
那么如何解决这个问题?某些 ActionBarSherlock 库功能是否与 2.3 兼容?
最佳答案
来自doc :
The themes should be defined in your manifest for the entire application or on a per-activity basis. You may also define the theme in the code of each activity before calling super.onCreate(Bundle). This must be done for every activity on which you extend from one of the 'Sherlock' activity base classes and intend to use the action bar. More information on how to specify a theme can be found in the official Android documentation.
您是否在 onCreate
方法中指定了这一点?
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
//other stuff here
}
关于java - Android:在 ActionBarSherlock 项目中的 Android 2.3 上,按钮的 findViewById 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525596/