ユーザーに、テーマの明るいオプションと暗いオプションを提供します。
ログのエラー:
原因: : 、、、または導関数を
java.lang.IllegalStateException
使用する必要があります。Theme.Sherlock
Theme.Sherlock.Light
Theme.Sherlock.Light.DarkActionBar
エラーsetContentView(R.layout.activity_main);
は 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 では、すべてうまく機能します。