0
在嘗試將Gingerbread支持添加到我的應用程序並失敗(在所有活動中崩潰)之後,我編寫了一些測試代碼來解決問題。getsupportactionbar()在Gingerbread上返回null /崩潰
我在擴展SherlockFragment活動。
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.widget.ListView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class MainActivity extends SherlockFragmentActivity {
ActionBar ab;
@Override
public void onCreate(Bundle savedInstanceState){
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String themestring = prefs.getString("theme","holo_colour");
if (themestring.equals("holo_dark_colour")){
setTheme(R.style.DarkBlueTheme);
}
if (themestring.equals("holo_colour")){
setTheme(R.style.BlueTheme);
}
setContentView(R.layout.gtest);
super.onCreate(savedInstanceState);
ab = getSupportActionBar(); //crash!
}
但我不能爲我的生命得到它停止崩潰的薑餅,其對4.0 +做工精細。
主題動態設置:
<style name="BlueTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">@style/BlueActionBar</item>
<item name="android:actionBarStyle">@style/BlueActionBar</item>
</style>
<style name="BlueActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#33b5e5</item>
<item name="background">#33b5e5</item>
<item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
<item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>
在此先感謝您的幫助!
你有沒有試過看看你的日誌,看看到底是什麼問題? – Michael
你的logcat崩潰在哪裏?快速發佈。 – GrIsHu