statefocused Boolean denoting focused or not focused true or false statepressed

Statefocused boolean denoting focused or not focused

This preview shows page 72 - 80 out of 112 pages.

state_focused Boolean denoting focused or not focused, true or false . state_pressed Boolean denoting pressed or not pressed, true or false .
Image of page 72

Subscribe to view the full document.

Defining a Color State List Resource You first must create a resource file defining the various states that you want to apply to your View object. To do so, you define a color resource that contains the <selector> element and the various <item> s and attributes that you want to apply.
Image of page 73
Defining a Color State List Resource (Cont’d) <selector xmlns:android= ""> <item android:state_disabled="true" android:color="#C0C0C0"/> <item android:state_enabled="true" android:color="#00FF00"/> <item android:state_pressed="true" android:color="#FFFF00"/> <item android:color="#000000"/> </selector>
Image of page 74

Subscribe to view the full document.

Defining a Button for Applying the State List Resource Now that we have a color state list resource, we can apply this value to one of our View objects. Below, we define a Button and set the textColor attribute to the state list resource file text_color.xml that we defined previously. <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" android:textColor="@color/text_color" />
Image of page 75
Working with Animation Android supports several kinds of animation. Two of the simplest varieties are: Frame-by-frame Frame-by-frame animation involves the display of a sequence of images in rapid succession. Tweening Tweened animation involves applying standard graphical transformations such as rotations and fades on a single image. The Android SDK provides some helper utilities for loading and using animation resources. These are found in android.view.animation.AnimationUtils class.
Image of page 76

Subscribe to view the full document.

Defining and Using Frame-by- Frame Animation Resources Frame-by-frame animation is often used when the content changes from frame to frame. This can be used for complex frame transitions much like a kid’s flip -book. To define frame-by-frame resources, take the following steps: 1. Save each frame graphic as an individual drawable resource. It may help to name your graphics sequentially, in the order in which they are displayed for example, frame1.png , frame2.png , and so on. 2. Define the animation set resource in an XML file within the res/drawable/ resource directory hierarchy. 3. Load, start, and stop the animation programmatically.
Image of page 77
Defining and Using Frame-by- Frame Animation Resources (Cont’d) <?xml version="1.0" encoding="utf-8" ?> <animation-list xmlns:android= "" android:oneshot="false"> <item android:drawable="@drawable/splash1" android:duration="500" /> <item android:drawable="@drawable/splash2" android:duration="500" /> <item android:drawable="@drawable/splash3" android:duration="500" /> </animation-list>
Image of page 78

Subscribe to view the full document.

Defining and Using Frame-by- Frame Animation Resources (Cont’d) Frame-by-frame animation set resources defined with <animation-list> are represented by the Drawable subclass AnimationDrawable .
Image of page 79
Image of page 80
  • Summer '16