Activity中ConfigChanges属性的用法

转自

http://www.apkbus.com/android-15504-1-1.html


CONFIG_FONT_SCALE 
CONFIG_MCC 
CONFIG_MNC 
CONFIG_LOCALE 
CONFIG_TOUCHSCREEN 
CONFIG_KEYBOARD 
CONFIG_NAVIGATION 
CONFIG_ORIENTATION 

设置方法:将下列字段用“|”符号分隔开,例如:“locale|navigation|orientation” 

<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> 

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);  
    }  
} 


你可能感兴趣的:(android,null,application,action,import,button)