[wish] setTheme for Application

RiverRaid

Active Member
Licensed User
Longtime User
Hy Erel,

as defining the look on an App with xml files is very, very powerful I tend to create the views via the Designer and style it later with custom xml-theme.

This works very good and is far better than using the "old" way:
B4X:
For i = 0 To FActivity.NumberOfViews - 1
        setColor(FActivity.GetView(i))
Next
the only problem is, that my app has different Themes from which the user can choose...

I found in the android - documentation following:
B4X:
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 ...
 setTheme(android.R.style.Theme_Light);
 setContentView(R.layout.linear_layout_3);
 }
Is it possible to implement that into B4A? It would be a biiiiiig step forwards Interface design....

:sign0162:
 

Informatix

Expert
Licensed User
Longtime User

The theme can be applied only when the activity is created, not after because setTheme must be called before setContentView in onCreate. A solution could be to create a StartActivity method with an additional Theme parameter.
 

RiverRaid

Active Member
Licensed User
Longtime User
Hi Informatix,

Thats a really great Idea! Would save a lot of uneccessary code and resourcess if the layout could be set viathe changeable xml files
 

aggelos

Member
Licensed User
Longtime User
I am reviving this thread because i think this thing MUST be implemented in b4a.
It would be a huge steap ahead in the theme area for b4a.

I thought how it can be done and the simplest way is :

1) in #Region Project Attributes the user will need to define the available themes
for example #themeslist red,blue,black

2) the user will define the file that will hold the theme to be loaded on start
for example #themesfile theme.txt

3) Between super.onCreate(savedInstanceState); and setContentView(layout);
we need java code to ...open the file if it exists. read it. check if the theme on file is on the #themeslist and then attempt to load the theme
This step must exist as a safeguard that the theme.txt contains a valid theme name

4) if it fails it will fall back to the manifest defined theme or the standard android theme

i dont think its that hard to be done.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…