Это старый вопрос, но, тем не менее, у меня, похоже, есть ответ.
В его простейшей форме.
<style name="BaseTheme" parent="@android:style/Theme.Black">
<item name="android:textColor">@color/white</item>
<item name="android:background">@color/black</item>
</style>
<style name="InvertedTheme" parent="BaseTheme">
<item name="android:textColor">@color/black</item>
<item name="android:background">@color/white</item>
</style>
В вашем наборе andmanmanifest;
<activity
android:name=".SomeActivity"
android:label="@string/app_name"
android:theme="@style/BaseTheme" />
Затем в вашем SomeActivity.java;
public class SomeActivity extends Activity {
static final String INVERTED_EXTRA = "inverted";
private void invertTheme() {
// to make the theme take effect we need to restart the activity
Intent inverted = new Intent(this, SomeActivity.class);
inverted.putExtra(INVERTED_EXTRA, true);
startActivity(inverted);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// must be before the setContentView
if (getIntent().getBooleanExtra(INVERTED_EXTRA, false))
setTheme(R.style.InvertedTheme);
}
setContentView(R.layout.some_layout);
...
Я пытался без запуска нового действия, но он не сбрасывает цвета.