My application has an option that allows the user to switch between a layout of daytime colors and another layout of night colors. My problem is that I do not know how to programmatically change the text color and background color of the Overflow Menu in Toolbar
(by styles.xml
file I know how to do, but programmatically not)? '
@Override
protected void onCreate(Bundle savedInstanceState) {
//setTheme(R.style.AppTheme2);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
tabLayout = (TabLayout) findViewById(R.id.tabs);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.nav_view);
floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
viewPager = (ViewPager) findViewById(R.id.container);
setSupportActionBar(toolbar);
}
Error message:
FATAL EXCEPTION: main
Process: info.no_ip.menda.pk_alerta_2, PID: 16365
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.no_ip.menda.pk_alerta_2/info.no_ip.menda.pk_alerta_2.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:199)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
at info.no_ip.menda.pk_alerta_2.MainActivity.onCreate(MainActivity.java:173)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
10-24 13:28:22.531 865-986/system_process I/ActivityManager: Delay finish: com.google.android.gms/.gass.chimera.PackageChangeBroadcastReceiver
10-24 13:28:22.599 865-910/system_process D/MobileDataStateTracker: default: setPolicyDataEnable(enabled=true)
10-24 13:28:22.615 865-5410/system_process W/ActivityManager: Force finishing activity info.no_ip.menda.pk_alerta_2/.MainActivity
[ 10-24 13:28:22.715 865: 5410 D/ ]