CS4521:   Mobile and Topics in Web Programming

Android: Applying Styles and Themes

      (see also Creating separate Style documents and applying styles to widgets AND defining Themes for Activities or Applications)

3 ways to Apply Styles and Themes (Also 4th way--directly in code not showing)

  • OPTION 1: Define the style attributes directly when defining the View -- DOES not separate style from content

    <EditText
       
    android:inputType="number"
        ...
    />

     

  • OPTION 2: Create a separate style file stored in anyname.xml inside of res/values with the styles defined and then apply to an individual View, by adding the style attribute to a View element in the XML for your layout.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>    <style name="Numbers">
         
    <item name="android:inputType">number</item>
     
        ...
       </style> ....more styles...... </resources>

    NOW apply it in your layout.xml file

<EditText
   
style="@style/Numbers"
    ...
/>
  • OPTION 3: using THEMES to an entire Activity or application, by adding the android:theme attribute to the <activity> or<application> element in the Android manifest.

 

<application           

        android:icon=“@drawable/icon”

         *******

        android:theme=“@android:style/Theme.Dialog >

        <activity ******

</application>

 

© Lynne Grewe