ActionBarSherlock 在 Android 应用程序中返回 Null 值
这是我的问题:
我一直在尝试在我的 Android 2.3 应用程序中获取 ActionBar。我决定使用 ActionBarSherlock。我通过导入 ZIP 并将其设为库来创建一个新项目。
我将它作为库添加到我当前的项目中。
然后它就无法工作,除非我删除了兼容性库(转换为Dalvik格式失败,错误1)
所以我删除了它,编译时没有更多错误。但当我尝试使用它时,它总是返回 null。我不确定我是否错过了一些小东西或什么,但这已经让我发疯有一段时间了。任何建议将不胜感激。这里还有一些代码片段:
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.StuMan"
android:versionCode="1"
android:versionName="1.0"
android:theme="@style/Theme.Sherlock">
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="13" />
然后是我在 Activity 中进行的调用:
import java.util.ArrayList;
import com.StuMan.R;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Window;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;
public class WelcomeGrid extends FragmentActivity{
private ArrayList<String> parts = new ArrayList<String>();
final String [] items=new String[]{"Classes", "Calendar", "To-Do List"};
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_grid);
requestWindowFeature(Window.FEATURE_ACTION_BAR_ITEM_TEXT);
Toast.makeText(getApplicationContext(), String.valueOf(getSupportActionBar().isShowing()), Toast.LENGTH_LONG);
GridView gv = (GridView)findViewById(R.id.gv_welcome);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
gv.setAdapter(adapter);
}
}
Here's my issue:
I've been trying to get an ActionBar in my Android 2.3 App. I decided to use ActionBarSherlock. I created a new project by importing the ZIP and then making it a library.
I added it as a library to my current project.
Then it wouldn't work unless I removed the compatibility library (Conversion to Dalvik format failed with error 1)
So I removed it and no more errors when compiling. But when I try to use it, it always returns null. I'm not sure if I'm missing something small or what but this has been driving me nuts for a while now. Any advice would be greatly appreciated. Here are some code snippets as well:
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.StuMan"
android:versionCode="1"
android:versionName="1.0"
android:theme="@style/Theme.Sherlock">
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="13" />
And then the call which I make in my Activity:
import java.util.ArrayList;
import com.StuMan.R;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Window;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;
public class WelcomeGrid extends FragmentActivity{
private ArrayList<String> parts = new ArrayList<String>();
final String [] items=new String[]{"Classes", "Calendar", "To-Do List"};
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_grid);
requestWindowFeature(Window.FEATURE_ACTION_BAR_ITEM_TEXT);
Toast.makeText(getApplicationContext(), String.valueOf(getSupportActionBar().isShowing()), Toast.LENGTH_LONG);
GridView gv = (GridView)findViewById(R.id.gv_welcome);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
gv.setAdapter(adapter);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要包含支持包,因为 ActionBarSherlock 包含支持包(并增强了它)。如果您检查 ActionBarSherlock 源代码,您将看到
android.support.v4.*
类。我让 getSupportActionBar() 重新调整为 null,直到我回去重新阅读使用说明,特别是有关父主题的说明。
包含在应用程序元素中
You don't need to include the support package as ActionBarSherlock contains the support package (and enhances it). If you check the ActionBarSherlock source you'll be about to see the
android.support.v4.*
classes.I was getting getSupportActionBar() retuning null till I went back to reread the usage instructions in particular about Parent Themes.
Include in the application element