我爲我的用戶提供主題明暗選項。如何在主要活動api中設置主題7?
在日誌中的錯誤:
Caused by:
java.lang.IllegalStateException
: You must useTheme.Sherlock
,Theme.Sherlock.Light
,Theme.Sherlock.Light.DarkActionBar
, or a derivative.
在setContentView(R.layout.activity_main);
在MainActivity會出現錯誤。
MainActivity
public class MainActivity extends SherlockFragmentActivity {.....public static int globalTheme;
Context context;
protected void onCreate(Bundle savedInstanceState) {
context = getApplicationContext();
mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = mySharedPreferences.edit();
editor.putBoolean("proxy", false);
editor.commit();
if (mySharedPreferences.getString(Preferences.PREF_THEME, "1").trim().equals("1"))
globalTheme = R.style.Sherlock___Theme;
else
globalTheme = R.style.Sherlock___Theme_Light;
setTheme(globalTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
我沒有在清單中添加的東西,因爲主題應該是動態變化 AndroidManifest.xml中
<uses-sdk android:minSdkVersion="7"
/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="com.belasheuski.activities.MyApplication"
>
<activity
android:name="com.belasheuski.activities.MainActivity"
android:label="@string/name_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
在API 7時出現此錯誤在API的所有15工作得很好。
很好的答案!非常感謝:)我寫了 '我不明白什麼是 」ForceOverflow「 和'<項目名稱=」 overlayedActionBarBackground「> @色/ overlayedActionBarDark ...'但它的工作,這是很好的)好發部位 – Malder 2013-02-26 20:43:33
ForceOverflow如果您的ActionBar只能顯示兩個項目(例如,在一個小設備上),但您知道您將擁有四個項目,則需要此選項。通常其中兩個只是被切斷,但是,使用ForceOverflow,您可以獲得該圖標以獲取更多菜單圖標。 – Trinimon 2013-02-26 21:56:37