Reputation: 3761
I'm developing an android application, in which I want to support multiple themes. Each theme will have different color combinations. How can I implement this with minimum coding.
Is there any way to implement this with the help of selector
?
For e.g. Say one of the activity displays a list of dynamic items. So instead of mentioning theme separately in each list item & them in list view & in background, can't I just mention the theme at one place and all the elements select appropriate background color etc. automatically?
Hope my question is clear.
Thank You
Upvotes: 1
Views: 1193
Reputation: 1523
I figured out how to have multiple skins (themes) in app. Not only can you change colors but also complete layout with this approach. Another good thing about this approach is that you don't ship all the skins (all the files) in your app but only the one you select when you build.
This scenario is needed if you have same app for different customers who want customized look of the app but functionality is the same.
[Activity(Label = "TEST_SKINOV", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
#if SKIN_DEFAULT
SetContentView(Resource.Layout.Main);
#endif
#if SKIN_BLUE
SetContentView(Resource.Layout.MainSkinBlue);
#endif
}
}
Edit your .csproj file with notepad and add skin name. Search for "DefineConstants" and add your skin name to it, like so:
<DefineConstants>TRACE;SKIN_DEFAULT</DefineConstants>
Also for all skin specific files do this to not include them in app to minimize app size:
<ItemGroup Condition="$(DefineConstants.Contains('SKIN_DEFAULT'))">
<AndroidResource Include="Resources\layout\Main.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
Upvotes: 0
Reputation: 35661
You can refer to this example.
How do I apply a style to all buttons of an Android application
It deals with buttons but the concept is the same for all UI elements.
You can set the theme at runtime with the Activity.setTheme method.
Upvotes: 1