I know that this question has been asked several times. but I can not find the problem in my case. I want to change the theme of the application, but my color is Primary, colorAccent, etc. Do not change.
my MainActivity extends BasicActivity. it looks like this:
public class MainActivity extends BasicActivity { public static String MY_PREFS = "MY_PREFS"; private SharedPreferences mySharedPreferences; int prefMode = Activity.MODE_PRIVATE; private Toolbar toolbar; private TabLayout tabLayout; private ViewPager viewPager; private ViewPagerAdapter adapter; private TextView tabOne, tabTwo, tabThree; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
this is my BasicActivity (in this case, I even simplified to show that the theme is taken from R.style):
public class BasicActivity extends AppCompatActivity { public static String MY_PREFS = "MY_PREFS"; int prefMode = Activity.MODE_PRIVATE; protected void onCreate(Bundle savedInstanceState) { JsonParser parser = new JsonParser(getApplicationContext()); int resourceId = this.getResources().getIdentifier(parser.getThemeID(), "style", this.getPackageName()); setTheme(R.style.c_2ecc71_BC6C2B); if (android.os.Build.VERSION.SDK_INT >= 19) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } super.onCreate(savedInstanceState); } }
and my XML:
<style name="c_2ecc71_BC6C2B" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">#2ecc71</item> <item name="colorPrimaryDark">#1ebc61</item> <item name="colorAccent">#BC6C2B</item> </style>
According to previous questions, this code should work, but in my case, views that have colorPrimary in their XML still load the old colors to those that were added to the new one, even if I set the theme before calling setContentView(R.layout.activity_main);
Thanks!
android themes
Max
source share