我正在学习如何使用ABS。代码在4.1上工作正常但是当我在2.2上运行相同的代码时,它会抛出异常
这是MainActivity.java
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class MainActivity extends SherlockFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ab.addTab(ab.newTab().setText("Beauty").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Cookery").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Health").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Relationship").setTabListener(new Listner()));
ab.addTab(ab.newTab().setText("Yoga Spirituality").setTabListener(new Listner()));
}
class Listner implements TabListener {
public void onTabReselected(Tab tab, FragmentTransaction ft) { }
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft = getSupportFragmentManager().beginTransaction();
switch (tab.getPosition()) {
case 0:
ft.add(android.R.id.content, new BEAUTYFragment());
ft.commit();
break;
case 1:
ft.add(android.R.id.content, new COOKERYFragment());
ft.commit();
break;
case 2:
ft.add(android.R.id.content, new HEALTHFragment());
ft.commit();
break;
case 3:
ft.add(android.R.id.content, new RELATIONSHIPFragment());
ft.commit();
break;
case 4:
ft.add(android.R.id.content, new YOGAFragment());
ft.commit();
break;
default:
break;
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) { }
}
}
这很明显:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sher"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat中的错误:
java.lang.NoClassDefFoundError:com.actionbarsherlock.R $ styleable
答案 0 :(得分:2)
您需要设置ABS主题或让您的主题从ABS主题扩展。需要处理ActionBar(3.0之前的设备)的向后兼容性
e.g。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
以下是有关ABS-theming
的一些信息