This article describes demos in App/Activity.
The first Animation shows the two Animation effects of starting another activity from one activity. The main method is as follows:
1 overridePendingTransition (int enterAnim, int exitAnim)
This method is called after startActivity () or finish () to specify an effect. The first parameter is the effect of the next activity, and the second parameter is the effect of the activity exit.
For more information about animation, see http://www.bkjia.com/kf/201111/109801.html.
The second CustomDialogActivity shows how an activity uses a custom theme to make it look like a dialog. Under the tag of the activity in ApiDemos Manifest. xml,
With this attribute: android: theme = "@ style/Theme. CustomDialog", a custom theme is referenced, In the styles. xml file:
1 <style name = "Theme. CustomDialog" parent = "android: style/Theme. Dialog">
2 <item name = "android: windowBackground"> @ drawable/filled_box </item>
3 </style> inherits from the built-in Theme. Dialog in/base/core/res/values/themes. xml. Its background is a custom shape, in filled_box.xml:
1 <shape xmlns: android = "http://schemas.android.com/apk/res/android">
2 <solid android: color = "# f0600000"/>
3 <stroke android: width = "3dp" color = "# ffff8080"/>
4 <corners android: radius = "3dp"/>
5 <padding android: left = "10dp" android: top = "10dp"
6 android: right = "10dp" android: bottom = "10dp"/>
7 </shape> solid filling, stroke, corners rounded corner, and padding. For details about shape, see this article: replace the gradient <solid> label with <gradient> to indicate the gradient:
1 <gradient
2 android: startColor = "#52 adcd"
3 android: endColor = "#1c87b1"
4 android: angle = "0"/> <! -Angle indicates the angle. 0 indicates the gradient from left to right. You can try it with several more values. This label cannot appear with the solid label at the same time. -!>
The third CustomTitle, how to customize a title, instead of using the original title of an activity, is mainly three sentences of code:
1 requestWindowFeature (Window. FEATURE_CUSTOM_TITLE );
2 setContentView (R. layout. custom_title );
3 getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. custom_title_1 );
The fourth DialogActivity shows how to make an activity look like a pop-up dialog. Similar to the second instance, it also adds the theme attribute to its activity tag. However, this reference
It is the system's own dialog theme: @ android: style/Theme. Dialog. Similarly to the third instance, The requestWindowFeature () method is also used. For this method,
There are a lot of introductions on the Internet, you can search for yourself, to a reference article: http://www.bkjia.com/kf/201202/120872.html
Fifth, let's take a look at PersistentState and SaveRestoreState. First, SaveRestoreState shows the effect of onSaveInstanceState () Saving the activity status. In fact, there is nothing in it,
OnSaveInstanceState () is called by default when the activity may be destory by the system. By default, the status of each view in the layout is recorded, such as the edittext content and the selected status of the checkedbox,
All you need to do is add an id for each control. If there is no id, the status cannot be saved. You can see the saveHierarchyState () in the source code PhoneWindow. java (). Generally, you do not need to rewrite it.
OnSaveInstanceState (), but if you want to save additional information except the UI state, such as the value of a member variable, You can override it.
Super. onSaveInstanceState (), which can be found in the official documentation.
PersistentState: This shows the State of saving edittext persistently using SharedPreferences, including the cursor position. It is mainly saved in onPause () and restored in onResume,
If you test the two examples, you can modify the values in the two edittexts and then rotate the mobile phone to make the screen horizontal, so that the activity will destory and then create.
The sixth example shows the ReceiveResult usage of startActivityForResult (), which can be used to select an email address or image from one activity to another,
After the selection is complete, the result is returned to the previous activity. I will follow the process to introduce the usage of this method, ReceiveResult --> SendResult, first call
StartActivityForResult (Intent intent, int requestCode) Start SendResult, and then process it in the SendResult activity. After processing, call setResult (int resultCode, Intent data ),
Return to ReceiveResult. After setResult (), call finish (). Finally, in ReceiveResult, override the onActivityResult (int requestCode, int resultCode, Intent data) method,
To process the returned results. Let's take a look at some details. For requestCode, it can be understood that A jumps to B and C or D to identify the activity to which A jumps. For resultCode, you can understand
If it is B, multiple values can be returned, such as OK or not OK. To distinguish multiple values returned by an activity, you can look at the Redirection example to enhance your understanding of startActivityForResult.
In addition, in onCreate () of receiveResult, mResults. setText (mResults. getText (), TextView. BufferType. EDITABLE );
Void android. widget. TextView. setText (CharSequence text, BufferType type) This method, you can refer to this article: http://www.bkjia.com/kf/201202/120874.html
It is best to look at this method with the source code, from the setText (CharSequence text, BufferType type) --> Editable. java --> SpannableStringBuilder. java of TextView. In fact, the original
CharSequence text is extended to SpannableStringBuilder to enable it to have append and other extension methods. There is also a factory mode. It is good to have time to read the source code.
The seventh step is to take a look at QuickContactsDemo. The first step is the QuickContactBadge control. You can view the configuration file on your own. Followed by ResourceCursorAdapter, which inherits from CursorAdapter and overwrites
The newView () method of CursorAdapter is actually a code that fills in the specified xml file with Inflater. Therefore, the newView () method in this example calls super () first (). newView () method.
Convert the layout to view, and then fill in the data in bindView. Finally, viewHolder caches the view in layout. viewHolder caches the control and reduces the overhead of findViewById () each time. It is a better way to optimize listview.
1 final static class ContactListItemCache {
2 public TextView nameView;
3 public QuickContactBadge photoView;
4 public CharArrayBuffer nameBuffer = new CharArrayBuffer (128 );
5}
6 ContactListItemCache cache = new ContactListItemCache ();
7 cache. nameView = (TextView) view. findViewById (R. id. name );
8 cache. photoView = (QuickContactBadge) view. findViewById (R. id. badge );
9 view. setTag (cache); the last three activities, a transparent background activity, a transparent and ambiguous background activity, and a background activity with your wallpaper all use custom theme, you can check it and put it in your own application.
This is a rough summary.
From ZircoN