Usage of configchanges properties in activity-general discussion-Android Development Forum-Android Development Forum-Android Development-Android forum-Mobile Internet portal-Powered by discuz!
By setting this property, the activity captures the state of the device, and the following is what can be identified:??
Config_font_scale
Config_mcc
Config_mnc
Config_locale
Config_touchscreen
Config_keyboard
Config_navigation
Config_orientation
Set method: Use the following fields with the "|" Symbols separated, for example: "Locale|navigation|orientation"
Value |
: |
Description |
Mcc |
: |
The IMSI Mobile Country Code (MCC) has Changed-that are, a SIM hasbeen detected and updated the MCC. Mobile country number, consisting of three digits, each country has Their own independent MCC, can identify the mobile phone users of the country. |
on! |
: |
The IMSI Mobile Network Code (MNC) has Changed-that is, a SIM hasbeen detected and updated the MNC. Mobile network number, in a country or region, used for district breakup Service Provider for machine users |
Locale |
: |
The locale has changed-for example, the user have selected a new language that text should is displayed in. The user's area is changed. |
Touchscreen |
: |
The touchscreen has changed. (This should never normally happen.) |
Keyboard |
: |
The keyboard type has changed-for example, the user have plugged in an external keyboard. The keyboard mode changes, for example: User access to external keyboard input. |
Keyboardhidden |
: |
The keyboard accessibility has changed-for example, the user have slid the keyboard out to expose it. User opens the phone hardware keyboard |
Navigation |
: |
The navigation type has changed. (This should never normally happen.) |
Orientation |
: |
The screen orientation have changed-that is and the user has rotated the device. Equipment rotation, landscape display and vertical display mode switching. |
Fontscale |
: |
The font scaling factor has changed-that are, the user has selected a new global font size. Global Font Size scaling changes |
The use of this property is explained by an example: first you need to modify the manifest of the project:
- <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
- ? ?? ? package= "Com.androidres.ConfigChangedTesting"
- ? ?? ? android:versioncode= "1"
- ? ?? ? android:versionname= "1.0.0" >
- ? ? <application android:icon= "@drawable/icon" android:label= "@string/app_name" >
- ? ?? ??? <activity android:name= ". Configchangedtesting "
- ? ?? ?? ?? ?? ?? ? android:label= "@string/app_name"
- ? ?? ?? ?? ?? ?? ? android:configchanges= "Keyboardhidden|orientation" >
- ? ?? ?? ?? ?<intent-filter>
- ? ?? ?? ?? ?? ? <action android:name= "Android.intent.action.MAIN"/>
- ? ?? ?? ?? ?? ? <category android:name= "Android.intent.category.LAUNCHER"/>
- ? ?? ?? ?? ?</intent-filter>
- ? ?? ??? </activity>
- ? ? </application>
- </manifest>
Copy Code
- <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
- ? ?? ? package= "Com.androidres.ConfigChangedTesting"
- ? ?? ? android:versioncode= "1"
- ? ?? ? android:versionname= "1.0.0" >
- ? ? <application android:icon= "@drawable/icon" android:label= "@string/app_name" >
- ? ?? ??? <activity android:name= ". Configchangedtesting "
- ? ?? ?? ?? ?? ?? ? android:label= "@string/app_name"
- ? ?? ?? ?? ?? ?? ? android:configchanges= "Keyboardhidden|orientation" >
- ? ?? ?? ?? ?<intent-filter>
- ? ?? ?? ?? ?? ? <action android:name= "Android.intent.action.MAIN"/>
- ? ?? ?? ?? ?? ? <category android:name= "Android.intent.category.LAUNCHER"/>
- ? ?? ?? ?? ?</intent-filter>
- ? ?? ??? </activity>
- ? ? </application>
- </manifest>
Copy Code
The Android:configchanges attribute is added to the activity to notify the program to call the Onconfigurationchanged () function when the specified attribute (Configuration changes) has changed. Create a layout UI:
- <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
- ? ? android:orientation= "Vertical"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Fill_parent"
- ? ? >
- <button
- ? ?? ??? Android:id= "@+id/pick"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Wrap_content"
- ? ? android:text= "Pick"
- ? ? />
- <button
- ? ?? ??? Android:id= "@+id/view"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Wrap_content"
- ? ? android:text= "View"
- ? ? />
- </LinearLayout>
Copy Code
- <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
- ? ? android:orientation= "Vertical"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Fill_parent"
- ? ? >
- <button
- ? ?? ??? Android:id= "@+id/pick"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Wrap_content"
- ? ? android:text= "Pick"
- ? ? />
- <button
- ? ?? ??? Android:id= "@+id/view"
- ? ? Android:layout_width= "Fill_parent"
- ? ? android:layout_height= "Wrap_content"
- ? ? android:text= "View"
- ? ? />
- </LinearLayout>
Copy Code
This simple UI contains two buttons, one of which is to select a contact from the Contacts list, and the other is to view the details of the currently selected contact.
<ignore_js_op>
1.jpg (11.7 KB, download count:)
Download attachments
? Save to album
2011-10-25 00:03 Upload
?
Java source code for the project:
- Import android.app.Activity;??
- Import android.content.Intent;??
- Import android.content.res.Configuration;??
- Import Android.net.Uri;??
- Import Android.os.Bundle;??
- Import android.provider.Contacts.People;??
- Import Android.view.View;??
- Import Android.widget.Button;??
- public class Configchangedtesting extends Activity {??
- ? ? /** called when the activity is first created. */
- ? ? static final int pick_request = 1337;??
- ? ? Button viewbutton=null;??
- ? ? Uri contact = null;??
- ? ? @Override
- ? ? public void OnCreate (Bundle savedinstancestate) {??
- ? ?? ??? Super.oncreate (savedinstancestate);??
- ? ?? ??? Setcontentview (R.layout.main);??
- ? ?? ??? Setupviews ();??
- ? ? }??
- ? ? public void onconfigurationchanged (Configuration newconfig) {??
- ? ?? ?? ?? ?? ??? Super.onconfigurationchanged (newconfig);? ?
- ? ?? ?? ?? ?? ??? Setupviews ();??
- ? ? }? ?
- ? ? /* (Non-javadoc)
- ? ??? * @see android.app.activity#onactivityresult (int, int, android.content.Intent)
- ? ??? */
- ? ? @Override
- ? ? protected void Onactivityresult (int requestcode, int resultcode, Intent data) {??
- ? ?? ??? TODO auto-generated method stub??
- ? ?? ??? Super.onactivityresult (Requestcode, ResultCode, data);??
- ? ?? ??? if (Requestcode = = pick_request) {??
- ? ?? ?? ?? ? if (RESULTCODE==RESULT_OK) {??
- ? ?? ?? ?? ?? ? Contact = Data.getdata ();??
- ? ?? ?? ?? ?? ? Viewbutton.setenabled (true);??
- ? ?? ?? ?? ?}??
- ? ?? ???}??
- ? ? }??
- ? ? private void Setupviews () {??
- ? ?? ??? Setcontentview (R.layout.main);??
- ? ?? ??? Button pickbtn = (button) Findviewbyid (R.id.pick);??
- ? ?? ??? Pickbtn.setonclicklistener (New View.onclicklistener () {??
- ? ?? ?? ?? ? public void OnClick (View v) {??
- ? ?? ?? ?? ?? ? TODO auto-generated method stub??
- ? ?? ?? ?? ?? ? Intent i=new Intent (Intent.action_pick,people.content_uri);??
- ? ?? ?? ?? ?? ? Startactivityforresult (i,pick_request);??
- ? ?? ?? ?? ?}??
- ? ?? ???});??
- ? ?? ??? Viewbutton = (Button) Findviewbyid (R.id.view);? ?
- ? ?? ??? Viewbutton.setonclicklistener (New View.onclicklistener () {??
- ? ?? ?? ?? ?? ?? ??? public void OnClick (view view) {??
- ? ?? ?? ?? ?? ?? ?? ?? ? startactivity (New Intent (Intent.action_view, contact));??
- ? ?? ?? ?? ?? ?? ???}??
- ? ?? ???});? ?
- ? ?? ??? Viewbutton.setenabled (contact!=null);??
- ? ? }??
- }
Copy Code
Usage of configchanges attribute in activity