Dynamic Theme Style in APEX 5.1

One of the new features of APEX 5.1 is the introduction of APEX_THEME API which enables you to change the application theme style by user.

A very nice APEX 5.0 feature is to allow users to change the theme style using the APEX_UTIL.SET_CURRENT_THEME_STYLE procedure (deprecated in 5.1) but this change is only applied at application level. Therefore if one user changes the theme style, then it will be changed for all users.

A new APEX API feature was released with APEX 5.1 called APEX_THEME. Using this package the theme style can now be changed and applied at user, session and application level.

Creating Theme Styles

A theme style can be easily created or changed using the Theme Roller feature found on the developer toolbar. There are a number of default styles available for theme 42 (Universal Theme) are Vita, Vista, Vita dark, Vita Red and Vita slate. It’s important to know that a theme must support styles to use this feature.

Set Theme Style by User

There are some several reasons why you may wish to configure “per user” Theme Styles, here are a few ideas:

  • User personalisation, High contrast styles for visually impaired users
  • Custom styles per customer/company
  • Per department colours
  • Per role; e.g. super users / managers with a different colour
  • Per company regional branch

For this example, I created a new style called GREEN. Here are the steps I took:

Step 1 – Create a select list to choose the theme style; I will call this P1_STYLE_ID. This is based on a query which retrieves available theme styles from an APEX data dictionary view for the DESKTOP user interface.

Note that the query has one condition to avoid showing the current style in the select list.

Step 2 – Then, we need a button (which submits to the page) to call the page process that will change the style.

Step 3 – Finally, create an APEX page process to call the procedure which will change the style.

The following example sets the current theme style to the value selected in :P1_STYLE_ID. The theme style is now stored as a user preference for the current user running the application.

And then …

Overall the APEX_THEME API is a wonderful feature of APEX 5.1 and can be used in many ways to make the application more user friendly.

About the Author

Rodrigo Mesquita

Oracle APEX Development Consultant

Explorer (UK) Ltd – Oracle awarding winning Platinum Partner and UKOUG Database & Engineered Systems Partner of the year 2016.

Rodrigo is a Development Consultant at Explorer. Rodrigo has an Oracle APEX Developer Expert Certification issued by Oracle and is an experienced software engineer with emphasis in analysis, design and development of bespoke Oracle applications utilising development tools such as PL/SQL, APEX and Forms   for a variety of international businesses.

 

You can follow Explorer via twitter page; @Explorerukltd