我正在尝试使用 ActionBarSherlock 库在旧设备中使用 Action Bar。我的应用程序运行在Android(4.2-Real device)
. 但是,当我尝试在运行它的旧银河选项卡中打开它时,Android 2.3.4
它崩溃了。这是我从中发现的logcat
这是一般活动的代码
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_general);
/*initial UI*/
initialUI();
/*Read file*/
String raw=readRawTextFile(this, R.raw.information);
/**/
MarkdownProcessor markDownPro = new MarkdownProcessor();
/**/
String getMarkDown = markDownPro.markdown(raw);
/**/
CharSequence cs = Html.fromHtml(getMarkDown);
/**/
text.setText(cs);
}
private void initialUI(){
text = (TextView)findViewById(R.id.text);
}
/**/
public static String readRawTextFile(Context ctx, int resId) {
InputStream inputStream=ctx.getResources().openRawResource(resId);
InputStreamReader inputreader=new InputStreamReader(inputStream);
BufferedReader buffreader=new BufferedReader(inputreader);
String line;
StringBuilder text=new StringBuilder();
try {
while ((line=buffreader.readLine())!=null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
return null;
}
return text.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.general, menu);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#003f84")));
return true;
}
}
一般活动编号 82 是
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#003f84")));
这里是清单文件的一些数据
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >
现在,另一个奇怪的是,如果它在 android 4.2 上运行,它不会显示我所描述的颜色
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#003f84")));
我需要提到的另一件事是,我在NullPointerException
里面定义了 tab 的类tabactivity
。我有另一个类来显示列表视图中的数据,在该类 ABS 中工作正常。因为,我在 Android 中使用标签导航。这是我的 Tab 类。(如果你需要的话)
public class Tabs extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs() ;
}
private void setTabs()
{
addTab("Info", R.drawable.tab_home, GeneralActivity.class);
addTab("Program", R.drawable.tab_search, ScheduleMainActivity.class);
addTab("Abstracts", R.drawable.tab_home,AbstractActivity.class);
addTab("Map", R.drawable.tab_map,LocationMarkers.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
这是我的样式文件
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>