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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值