Android Tutorial Theme based on version Tutorial

Dave O

Well-Known Member
Licensed User
Longtime User
@barx , thanks for explaining this. I was testing an app on my 5.x phone, and everything was fine, then tried it on a 4.x device and saw that the theme was screwy. I fixed it using your tutorial, but I replaced the manual XML-file-editing with the CreateResource function in the manifest editor.

Here's how I made the same theme (based on Holo Light) for 4.x and 5.x:

B4X:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
CreateResource(values-v11, theme.xml,
<resources>
   <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
     <item name="android:colorPrimary">#12DB00</item> <!-- action bar -->
     <item name="android:colorPrimaryDark">#096E00</item> <!-- status bar -->
     <item name="android:colorAccent">#12DB00</item> <!-- checkboxes,, switches,, msgbox buttons in Android 6.x -->
     <item name="android:textColor">#000000</item> <!-- ? -->
    <item name="android:textColorPrimary">#000000</item> <!-- msgbox text in Android 6.x -->
      <item name="android:textColorSecondary">#606060</item> <!-- inactive editText line,, scrollbar -->
     <item name="android:textColorLink">#096E00</item>
     <item name="android:textColorHighlight">#12DB00</item> <!-- menu text,, msgbox title -->
   </style>
</resources>
)
CreateResource(values-v21, theme.xml,
<resources>
   <style name="MyAppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
     <item name="android:colorPrimary">#12DB00</item> <!-- action bar -->
     <item name="android:colorPrimaryDark">#096E00</item> <!-- status bar -->
     <item name="android:colorAccent">#12DB00</item> <!-- checkboxes,, switches,, msgbox buttons in Android 6.x -->
     <item name="android:textColor">#000000</item> <!-- ? -->
    <item name="android:textColorPrimary">#000000</item> <!-- msgbox text in Android 6.x -->
      <item name="android:textColorSecondary">#606060</item> <!-- inactive editText line,, scrollbar -->
     <item name="android:textColorLink">#096E00</item>
     <item name="android:textColorHighlight">#12DB00</item> <!-- menu text,, msgbox title -->
   </style>
</resources>
)

Thanks again!
 
Last edited:

Ederson Kerber

Member
Licensed User
Good evening, @Erel @barx

When trying to use the theme together as an attribute:

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: false
#Extends: android.support.v7.app.AppCompatActivity
#End Region

I get the error below: java.lang.RuntimeException: Unable to start activity ComponentInfo{barxdroid.VersionThemeDemo/barxdroid.VersionThemeDemo.main}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.


When taking the attribute "Extends: android.support.v7.app.AppCompatActivity" the error does not happen, however, I must use the same in my application.


Thanks, I appreciate that you can help.
 

Attachments

  • manifest.JPG
    51.7 KB · Views: 450
  • log.JPG
    118.9 KB · Views: 457
  • main.JPG
    54.2 KB · Views: 422
Cookies are required to use this site. You must accept them to continue using the site. Learn more…