👀 Watch Rust 🦀 live coding videos on our YouTube Channel.

Introduction #

This tutorial will familiarize you with the theme-ing capabilities of Android API. You can set background color, image, etc. on widgets. However, there are some customizations that can only be performed by using the theme-ing facility. Examples of this include change the colors/images of a top-level window like an Activity or Dialog.

Defining themes in XML #

Here’s an example of defining a theme in XML, this goes in the styles.xml file in the <your project>/res/values/styles.xml file; you can define colors, drawables, and lots of other resources here that get referenced in your theme:

  <!-- Base application theme is the default theme. -->
  <style name="Theme" parent="android:Theme">

  <!-- Variation on our application theme that has a translucent
 background. -->
  <style name="Theme.Translucent">
    <item name="android:windowBackground">@drawable/translucent_background</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:colorForeground">#fff</item>

  <!-- Variation on our application theme that has a transparent
background; this example completely removes the background,
allowing the activity to decide how to composite. -->
  <style name="Theme.Transparent">
    <item name="android:windowBackground">@drawable/transparent_background</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:colorForeground">#fff</item>
  <style name="TextAppearance.Theme.PlainText"
    <item name="android:textStyle">normal</item>


This is how you reference this theme in an Activity:

public class WidgetActivity extends Activity {

@Override protected void onCreate(Bundle bundle) {

        "sub-Activity WidgetActivity being creation: start");



        "sub-Activity WidgetActivity being creation: end");


}//end class WidgetActivity

The Android SDK Manual has a lot more information on styles and themes and how assets and content are used and created.

📦 Install our useful Rust command line apps using cargo install r3bl-cmdr (they are from the r3bl-open-core project):
  • 🐱giti: run interactive git commands with confidence in your terminal
  • 🦜edi: edit Markdown with style in your terminal

giti in action

edi in action

Related Posts