Android Question Custom Theme error

rudystyle

Member
Licensed User
Longtime User
I tried to use a custom theme but I always get the following error

AndroidManifest.xml:19: error: Error: No resource found that matches the given name (at 'theme' with value '@style/MyTheme').

I created a theme.xml under res/values folder. The theme.xml file has the following content

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name="MyTheme" parent="Theme.Holo.Light">
</style>

</resources>

My manifest file has
SetApplicationAttribute(android:theme, "style/MyTheme")

I also tried
SetApplicationAttribute(android:theme, "@android:style/MyTheme")

But both don't work. I am using platforms\android-21\android.jar in configure paths


 

JTmartins

Active Member
Licensed User
Longtime User
I think you have to make the theme.xml as a read only file or it will be deleted at compile time.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
or use an additionalres directive and create a new path for the theme.xml (or other resources)
 
Upvote 0

rudystyle

Member
Licensed User
Longtime User
Thanks for the inputs. I had the res folder out side the Object folder. Found out that it has to be inside the Objects folder.
Also put the res folder as Read only otherwise compiler deletes the files
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are using B4A v5.80 then the best way is to use CreateResource.

For example to create a light theme based on the native theme on both Android 4 and Android 5+:
B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values-v20, theme.xml,
<resources>
  <style
  name="LightTheme" parent="@android:style/Theme.Material.Light">
  </style>
</resources>
)
CreateResource(values-v14, theme.xml,
<resources>
  <style
  name="LightTheme" parent="@android:style/Theme.Holo.Light">
  </style>
</resources>
)
 
Upvote 0
Top