Modifying theme colors dynamically during program execution

Currently, I am working on implementing a remote styling feature. I have been unable to figure out how to modify the colorPrimary value after the activity has been created and the remote style is fetched through the API. While I understand that theme styling is typically immutable, I am hopeful that there might be a way to instruct all Material components, status bar, and menu bar to adopt specific colors once they are ready for use. Any suggestions?

Below is my theme code for reference:

<style name="OrderingTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorPrimary</item>
 </style>

Thank you!

Answer №1

Modifying the theme color dynamically is not possible as themes are static. However, you can alter the StatusBar color using Window.setStatusBarColor() and adjust the navigation bar color with Window.setNavigationBarColor(). If necessary, you can store a color in a variable and change it based on the selected mode/theme.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Activate two divs simultaneously by hovering over one

I have two divs located in the footer of my website and they can be seen here: divs in question Below is the code for these divs: .upNextCard{ /* Rectangle 68 */ position: absolute; width: 214.29px; height: 255.69px; margin-left:300px; margin ...

Static express fails to load CSS files from the main folder

When my app is loaded from a url like: server.com/pdf/12345, it tries to find static files at GET /pdf/12345/assets/css/stylesheet.css and returns a 404 error. I've been struggling to get it to search for the files in /public/assets instead. I've ...

Error encountered when sharing a video on Facebook wall using an Android device: Null Pointer Exception

My application is designed to enable users to upload videos to their Facebook profiles. I have encountered a null pointer exception in the following code, which is similar to many other examples of working code: Below is my main class: Session session; F ...

Accessing and interpreting the JSON response from a resource saved within the application

In my app, I am reading a JSON response from a .json file that is stored within the application. The code snippet below shows how I am achieving this: private String readJSONResponse(){ InputStream is = getResources().openRawResource(R.raw.json_da ...

Android App Facing Runtime Exception Crashes

I recently started learning Android development, and I might have made a mistake while creating the interface. Instead of using XML, I coded the interface in Java. However, every time I launch the application on the emulator, it crashes. Here is the stack ...

What is the best way to apply the CssClass "active" when clicking on a link

How can we update the cssClass of a link button on each click event, considering that the page refreshes every time? Currently, when I click on any LinkButton, the default behavior sets the cssClass to Plus LinkButton. ---index.aspx----------- <ul cl ...

Creating a repeated design using linear gradients in CSS

As I venture into the realm of Photoshop patterns for the first time, I am working on a webpage where I plan to incorporate these patterns to enhance the background. The pattern I have discovered measures 120x120 px. If I were to stop here, I would simpl ...

Ways to create an underlined text effect using CSS

Can you help me style my two <a> tags so they appear underlined? I can't use border-bottom: dashed 10px because the lines are thin and there is too much space between them. .t1 { color: #8bb09e; } .t2 { color: #ffee90; } <a href= ...

Trying to open the contacts on the Galaxy S causes the app to crash

Is there a way to access contacts on the Galaxy S? Here's the code I'm using: Intent intent = new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI); startActivity(intent); This code works on the emulator and Samsung i5700. However, when I run i ...

What is the reason behind asp:Textbox occasionally appending "text" to the CSS class in the final HTML output?

Here's the code snippet: <asp:TextBox ID="txtAddress" CssClass="s175" runat="server" MaxLength="30" placeholder="Street"></asp:TextBox> After rendering, it looks like this: <input name="ctl00$LeftColumnContent$txtAddress" type="text" ...

Navigating through a PHP table, tracking your progress with a

I have encountered a problem that I need help with. I have been searching the internet for information on how to add a progress bar to my PHP code. Most solutions I found use the style method to display the progress percentage. In the image below, you can ...

Discrepancy in Gson behavior between generated APK and debug mode

My current task involves parsing data received from a notification bundle: String intervalsData = data.getString(ARG_INTERVAL, "[]"); Type intervalListType = new TypeToken<List<Interval>>() {}.getType(); List<Interval> intervalList = Con ...

What is the process for uploading a raw image with AJAX?

Looking for advice on the best way to upload a base64 encoded image from a mobile device's camera using PhoneGap to store it on a server. Any recommended approaches? Encountering Error 414 (Request-URI Too Large) when attempting to include the base64 ...

Creating a multi-tiered dropdown menu in the navigation bar with the help of Bootstrap 4 and Angular 7

My goal is to implement a multilevel dropdown using bootstrap 4 and angular 7. While I successfully created a simple dropdown in the navbar following the official bootstrap documentation, I struggled to make the multilevel dropdown work. After referring ...

Using Javascript to trigger a setTimeout function after the user's mouse leaves

There is a div that pops up when the user's mouse exits the webpage, containing a survey pertaining to my website. I want to avoid prompting users to take the survey if they move their cursor out of the page within the first few minutes of browsing. ...

What is the best way to display a Country's information from the dropdown menu in the Local Weather application?

I have been working on a Local Weather app that includes a dropdown menu where users can click on a location to view information such as City, Country, and temperature. However, I encountered an issue where the information does not appear consistently ever ...

Create a Div that smoothly transitions in and out, periodically appearing and disappearing

Can anyone assist me in implementing a feature where a message (div) displays on my website for two minutes every 15 minutes? Any advice or script would be greatly appreciated. Thank you in advance! ...

Navbar links in Bootstrap unexpectedly expanding in width

My website has a navigation menu that looks like this: https://i.stack.imgur.com/1R8mv.png However, when I click on a menu item, the link container inherits the width of the dropdown menu. Is there a way to prevent this using purely CSS? I am currently ...

Is there a way to alter the background color of an entire section once a child element within it is clicked?

I am currently working on a personal project where I am attempting to replicate the design shown below: The most challenging part for me right now is implementing the functionality that when one of the 6 differently colored boxes is clicked, additional in ...

Managing profile pictures on Firebase Storage

Currently developing a social app for Android using Firebase. Users can upload up to three images each, stored via FirebaseStorage. Activity where users add photos To name the photos, I am utilizing the user's unique ID. For instance, a user's ...