Creating the User Interface

  1. Create 2 XML layout files in the MyFirstRichNotification/app/src/main/res/layout directory:
    1. Create the activity_rich_notification.xml file. This is the basic layout.
      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                       xmlns:app="http://schemas.android.com/apk/res-auto"
                                                       xmlns:tools="http://schemas.android.com/tools"
                                                       android:layout_width="match_parent"
                                                       android:layout_height="wrap_content"
                                                       android:fitsSystemWindows="true"
                                                       tools:context="com.samsung.android.myfirstrichnotification.RichNotificationActivity">
      
         <android.support.design.widget.AppBarLayout android:layout_width="match_parent"
                                                     android:layout_height="wrap_content"
                                                     android:theme="@style/AppTheme.AppBarOverlay">
      
            <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
                                               android:layout_width="match_parent"
                                               android:layout_height="?attr/actionBarSize"
                                               android:background="?attr/colorPrimary"
                                               app:popupTheme="@style/AppTheme.PopupOverlay" />
      
         </android.support.design.widget.AppBarLayout>
      
         <android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
                                                     android:layout_height="match_parent"
                                                     app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <include layout="@layout/content_rich_notification" />
         </android.support.v4.widget.NestedScrollView>
      
      </android.support.design.widget.CoordinatorLayout>
      
    2. Create the content_rich_notification.xml file.

      It is possible that the “cannot resolve symbol” appears at this stage. This issue is resolved after the next step as you define the necessary strings.

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >
      
         <Spinner android:id="@+id/spinner1"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:entries="@array/template_arrays"
                  android:prompt="@string/template_prompt" />
      
         <Button android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:onClick="onSendClick"
                 android:text="@string/send" />
      
      </LinearLayout>
      
  2. To set up the default value of the layout item, modify the strings.xml file in the MyFirstRichNotification/app/src/main/res/values directory.

    The template_arrays in the spinner item have 6 different selectable values. These values are Small Header, Medium Header, Large Header, Full Header, Event, and Image.

    <resources>
       <string name="app_name">MyFirstRichNotification</string>
       <string name="action_settings">Settings</string>
    
       <string name="template_prompt">Choose a template</string>
       <string-array name="template_arrays">
          <item>Small Header</item>
          <item>Medium Header</item>
          <item>Large Header</item>
          <item>Full Header</item>
          <item>Event</item>
          <item>Image</item>
       </string-array>
    
       <string name="send">Send</string>
       <string name="title_activity_my_callback">MyCallbackActivity</string>
    
    </resources>