Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

best way to change background and text color for different elements across multiple activities

$
0
0

im working on an app that has a settings activity that allows the user to change the background and text color of different elements in this app (buttons, labels, spinners, etc). once saved, id like to apply these color changes to every activity in the app. is there a good way to do this? my thoughts on possible solutions:

  • every activity that loads, iterate through each element and change the color based on element type (foreach button .... foreach label... foreach edittext)
    ``

  • maybe create a custom control for each element that just has a static value for each color that will be used across all the same element type?

  • hardcode the color change in each activity via some function called in the load
    ie
    private void loadColors()
    {
    _btn.SetTextColor(color_val);
    _btn.Background.SetColorFilter(color_val, PorterDuff.Mode.Multiply);
    .....
    }

  • create a resource file that can be edited and have the different elements point to that file for its color
    ie maybe like

    #3498DB
    #77D065
    #B455B6
    #738182

and in layout.xml
...
android:background="@color/my_blue"

...and the settings activity can edit the resource file

are there any better way to approach this?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>