Android API Demos learning-Activity part

Source: Internet
Author: User

1. Hello WorldBasic display Android API Demos Learning (1)-Hello World
 2. Save & Restore StateSave and restore the UI status. Android API Demos Learning (2)-Save & Restore State3. Persistent StatePermanently save user preferences. Android API Demos Learning (3)-Persistent State4. Receive ResultStart other activities and receive returned data from the Child activity. Android API Demos Learning (4)-Receive Result5. ForwardingWhen another Activity is started, the current Activity is removed from the history stack of the Activity, that is, the previous Activity is not returned when the BACK key is pressed. The implementation is very simple, that is, when other activities are started, use finish () to end the current Activity. Public void onClick (View v ){
// Here we start the next activity, and then call finish ()
// So that our own will stop running and be removed from
// History stack.
Intent intent = new Intent ();
Intent. setClass (Forwarding. this, ForwardTarget. class );
StartActivity (intent );
Finish ();
}6. RedirectionUse the stored data to determine which Activity to start. In this example, check whether the data is saved. If the data is not saved, enter RedirectGetter. If yes, it is displayed in RedirectMain. If (! LoadPrefs () {Intent intent = new Intent (this, RedirectGetter. class); startActivityForResult (intent, INIT_TEXT_REQUEST );}7. TranslucentDisplay a translucent background. Www.2cto.com first look at AndroidManifest. definition in xml: <activity android: name = ". app. translucentActivity "android: label =" @ string/activity_translucent "android: theme =" @ style/Theme. translucent "> Theme is called here. translucent topic in/res/values/styles. <style name = "Theme. translucent "parent =" android: style/Theme. translucent "> <item name =" android: windowBackground "> @ drawable/translucent_background </item> <item name =" androi D: windowNoTitle "> true </item> <item name =" android: colorForeground "> # fff </item> </style> android: windowBackground in/res/values/colors. in xml, it is set to # e0000000, and the previous e0 sets transparency.8. TranslucentBlurA translucent background with special effects. <Style name = "Theme. transparent "> <item name =" android: Movie wistranslucent "> true </item> <item name =" android: windowAnimationStyle "> @ android: style/Animation. translucent </item> <item name = "android: windowBackground"> @ drawable/transparent_background </item> <item name = "android: windowNoTitle "> true </item> <item name =" android: colorForeground "> # fff </item> </style> android: windowAnimationStyle sets the jump animation effect. GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_BLUR_BEHIND, WindowManager. LayoutParams. FLAG_BLUR_BEHIND); The above sentence achieves fuzzy effect.9. Dialog ActivitySet the topic of the Activity to Dialog to make the Activity look like a Dialog box. <Activity android: name = ". app. dialogActivity "android: label =" @ string/activity_dialog "android: theme =" @ android: style/Theme. dialog "> You can also set the icon above the Dialog box, as shown below: getWindow (). setFeatureDrawableResource (Window. FEATURE_LEFT_ICON, android. r. drawable. ic_dialog_alert );10. Custom TitleCustomize the title bar. RequestWindowFeature (Window. FEATURE_CUSTOM_TITLE); setContentView (R. layout. custom_title); getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. custom_title_1); here, requestWindowFeature is the Window attribute for activating the extension. The Window is set here. FEATURE_CUSTOM_TITLE is a custom title. GetWindow (). setFeatureInt defines the title style. <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/screen" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <TextView android: id = "@ + id/left_text" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" android: text = "@ string/custom_title_left"/> <TextView android: id = "@ + id/right_text" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentRight = "true" android: text = "@ string/custom_title_right"/> </RelativeLayout> defines the relative layout. The title is divided into two parts: left and right.11. AnimationCustomizes the animation when two Activity switches. Public void onClick (View v) {// Request the next activity transition (here starting a new one ). startActivity (new Intent (Animation. this, Controls1.class); // Supply a custom animation. this one will just fade the new // activity on top. note that we need to also supply an animation // (here just doing nothing for the same amount of time) for the // old activity to prevent it from going away too s Oon. overridePendingTransition (R. anim. fade, R. anim. hold);} overridePendingTransition (int enterAnim, int exitAnim) must be defined in StartActivity (Intent) or Activity. finish () to define the animation when two activities are switched. enterAnim defines the animation effect when a new Activity appears, and exitAnim defines the animation effect when the current Activity exits. A. first look at fade. xml and hold. xml: <alpha xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/accelerate_interpolator" android: fromAlpha = "0.0" android: toAlpha = "1.0" android: duration = "@ android: integer/config_longAnimTime"/> <translate xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/accelerate_interpolator" android: fromXDel Ta = "0" android: toXDelta = "0" android: duration = "@ android: integer/config_longAnimTime"/> <alpha> defines an animation with transparency changes, <translate> define a translation animation. Android: interpolator defines the animation change rate, which can be acceleration, deceleration, or repetition. Android: duration defines the animation time. B. look at zoom_enter.xml and zoom_exit.xml <set xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/decelerate_interpolator"> <scale android: fromXScale = "2.0" android: toXScale = "1.0" android: fromYScale = "2.0" android: toYScale = "1.0" android: Large Tx = "50% p" android: Large ty = "50% p" android: duration = "@ android: integer/config_mediumAnimTime"/> </set> <set xmlns: android = "http: // SC Hemas.android.com/apk/res/android "android: interpolator =" @ android: anim/decelerate_interpolator "android: zAdjustment =" top "> <scale android: fromXScale =" 1.0 "android: toXScale = ". 5 "android: fromYScale =" 1.0 "android: toYScale = ". 5 "android: Short Tx =" 50% p "android: Short ty =" 50% p "android: duration =" @ android: integer/config_mediumAnimTime "/> <alpha android: fromAlpha = "1.0" android: toAlpha = "0" android: duration = "@ Ndroid: integer/config_mediumAnimTime "/> </set> <set> is an animated container. Www.2cto.com <scale> is a scaling animation. Another animation is <rotate>, that is, the rotation animation.12. Screen OrientationDifferent screen orientation. SetRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_UNSPECIFIED); there are 12 orientations in Android, which have their meanings in the comments: final static int mOrientationValues [] = new int [] {ActivityInfo. SCREEN_ORIENTATION_UNSPECIFIED, // default, no ActivityInfo defined. SCREEN_ORIENTATION_LANDSCAPE, // horizontal, larger than ActivityInfo. SCREEN_ORIENTATION_PORTRAIT, // portrait, tall than ActivityInfo. SCREEN_ORIENTATION_USER, // the user's current preferred direction ActivityInfo. SCREEN_ORIENTATION_BEHIND, // and background Activity in the stack has the same direction as ActivityInfo. SCREEN_ORIENTATION_SENSOR, // automatically changes ActivityInfo according to the direction of the physical sensor. SCREEN_ORIENTATION_NOSENSOR, // ActivityInfo is not changed based on the sensor. SCREEN_ORIENTATION_SENSOR_LANDSCAPE, // display ActivityInfo horizontally Based on the sensor. SCREEN_ORIENTATION_SENSOR_PORTRAIT, // display ActivityInfo vertically according to the sensor. SCREEN_ORIENTATION_REVERSE_LANDSCAPE, // The reverse horizontal display is after 180 degrees. ActivityInfo. SCREEN_ORIENTATION_REVERSE_PORTRAIT, // display ActivityInfo. SCREEN_ORIENTATION_FULL_SENSOR vertically, // supports rotation in four directions };13. Custom DialogCustom dialog box. <Activity android: name = ". app. customDialogActivity "android: label =" @ string/activity_custom_dialog "android: theme =" @ style/Theme. customDialog "> In/res/values/styles. theme. custonDialog: <style name = "Theme. customDialog "parent =" android: style/Theme. dialog "> <item name =" android: windowBackground "> @ drawable/filled_box </item> </style> defines the background in/drawable/filled_box.xml: <shape xmlns: android = "http://schemas.a Ndroid.com/apk/res/android "> <solid android: color =" # f0600000 "/> <stroke android: width =" 3dp "color =" # ffff8080 "/> <corners android: radius = "3dp"/> <padding android: left = "10dp" android: top = "10dp" android: right = "10dp" android: bottom = "10dp"/> </shape> <shape> the default value is square. solid indicates the fill color. stroke indicates the width and color of the paint brush. corners defines the arc radius of the corner, padding is the padding.14. Reorder On LaunchSorts the running stacks of the Activity. In this example, there are four activities, which are replaced by ABCD. If the stack is started in order, the stack is ABCD, and D indicates the top. If B is started in D, intent is used when the following options are set. addFlags (Intent. FLAG_ACTIVITY_REORDER_TO_FRONT); then start B, the stack will become ACDB, and B will be moved to the top of the heap. A new B is activated if no settings are used.15. WallpaperUse a desktop wallpaper as the background. <Activity android: name = ". app. wallpaperActivity "android: label =" @ string/activity_wallpaper "android: theme =" @ style/Theme. wallpaper "> In/res/values/styles. theme. wallpaper: <style name = "Theme. wallpaper "parent =" android: style/Theme. wallpaper "> <item name =" android: colorForeground "> # fff </item> </style>16. Set WallpaperSet the wallpaper. Final WallpaperManager wallpaperManager = WallpaperManager. getInstance (this); final Drawable wallpaperDrawable = wallpaperManager. getDrawable (); final ImageView imageView = (ImageView) findViewById (R. id. imageview); imageView. setDrawingCacheEnabled (true); imageView. setImageDrawable (wallpaperDrawable); gets the current wallpaper and displays it in the current imageView. Randomize. setOnClickListener (new OnClickListener () {public void onClick (View view) {int mColor = (int) Math. floor (Math. random () * mColors. length); wallpaperDrawable. setColorFilter (mColors [mColor], PorterDuff. mode. MULTIPLY); imageView. setImageDrawable (wallpaperDrawable); imageView. invalidate () ;}}); then a color is obtained, the wallpaper is combined in a filtering method, and the effect is previewed in the imageView. WallpaperManager. setBitmap (imageView. getDrawingCache (); getDrawingCache extracts the cached bitmap from imageView and sets it to the current wallpaper.

From Xiao He's exposure to sharp corners

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.