Android仿QQ的设置与帮助使用PreferenceActivity 与 自定义PreferenceActivity

先看下效果:

效果图1

 

 

效果图2

 

 

效果图3

 

 

效果图4

 

 

AndroidManifest.xml




    
        
            
                
                
            
        
        
        
        
        
        
        
    

 


SettingActivity.java

package com.nj.demo;


import android.os.Bundle;
import android.preference.PreferenceActivity;

/**
 * 设置
 *
 */
public class SettingActivity extends PreferenceActivity{

	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        
 
        addPreferencesFromResource(R.xml.setting_preference);

    }
}


 

FriendInfoActivity.java

package com.nj.demo;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 好友信息
 *
 */
public class FriendInfoActivity extends Activity{

	private TextView mChangeCommentTextView;
	
	private EditText mCommentEditText;
	
	private boolean  mBCommentEditable;
	
	private InputMethodManager mKeyBorad;
	
	private String mCommentTmpString;			
	
	
	
	private LinearLayout mQzone;
	private LinearLayout mMaiLayout;
	private LinearLayout mChat;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.info_friend);
		
		init();
	}

	
	private void init()
	{		
		
		mChangeCommentTextView = (TextView) findViewById(R.id.change_comment);
		mChangeCommentTextView.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switchCommentState();
			}
		});
		
		mCommentEditText = (EditText) findViewById(R.id.edit_comment);
		
		mBCommentEditable = false;

		mKeyBorad = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);  

		
		View view1 = findViewById(R.id.info_qzone_mail);
		mQzone = (LinearLayout) view1.findViewById(R.id.qzone);
		mQzone.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(FriendInfoActivity.this, "You Press QZONE", Toast.LENGTH_SHORT).show();
			}
		});
		
		mMaiLayout = (LinearLayout) view1.findViewById(R.id.mail);
		mMaiLayout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(FriendInfoActivity.this, "You Press Main", Toast.LENGTH_SHORT).show();
			}
		});
		
		mChat = (LinearLayout) view1.findViewById(R.id.chat);
		mChat.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(FriendInfoActivity.this, "You Press Chat", Toast.LENGTH_SHORT).show();				
			}
		});
	}
	
	
	



	private void switchCommentState()
	{
		
		
		if (mBCommentEditable)
		{
			mBCommentEditable = false;
			mCommentEditText.setFocusableInTouchMode(false);
			mCommentEditText.setFocusable(false);
			
			
			mChangeCommentTextView.setText("修改");   


			boolean ret = mKeyBorad.hideSoftInputFromWindow(mCommentEditText.getWindowToken(), 0);
			if (ret == false)	
			{
				mCommentEditText.setText(mCommentTmpString);
			}
		}else{			
			mBCommentEditable = true;			
			mCommentEditText.setFocusableInTouchMode(true);
			mCommentEditText.setFocusable(true);		
		
			mChangeCommentTextView.setText("确定");
	
			mKeyBorad.showSoftInput(mCommentEditText, 0);
			
			mCommentTmpString = mCommentEditText.getText().toString();
		}
	}
}


 

 

SkinActivity.java

package com.nj.demo;

import java.util.ArrayList;
import java.util.List;

import com.nj.demo.adapter.SkinListAdapter;
import com.nj.demo.adapter.SkinListItemData;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * 更换皮肤
 *
 */
public class SkinActivity extends Activity{
	
	private final int skinIconID[] = {R.drawable.skinpic_blue,
										R.drawable.skinpic_green,
										R.drawable.skinpic_pink,
										R.drawable.skinpic_snow};
	
	private final String text[] = {"蓝水静溢", "绿雾晨光", "粉色花语", "银装素裹"};
	
	private final int uncheckIcon = R.drawable.themeradio;
	
	private ListView mListView;
	
	private SkinListAdapter mSkinListAdapter;
	
	private TextView mTitleTextView;
	
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        setContentView(R.layout.skin_main_layout);
        
        init();
    }
	
	
	
	private void init()
	{
		mListView = (ListView) findViewById(R.id.themelist);
		
		mSkinListAdapter = new SkinListAdapter(this, getItemList());
		
		mListView.setAdapter(mSkinListAdapter);
		
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				mSkinListAdapter.setSelect(position);
				mTitleTextView.setBackgroundResource(skinIconID[position]);
			}
		});
		

		mTitleTextView = (TextView) findViewById(R.id.skinTitle);
	
		
	}
	
	
	private List getItemList()
	{
		List list = new ArrayList();
		
		for(int i = 0; i < 4; i++)
		{
			SkinListItemData data = new SkinListItemData();
			data.mImageViewLeftID = skinIconID[i];
			data.mTextView = text[i];
			data.mImageViewRightID = uncheckIcon;
			list.add(data);
		}
		
		
		return list;
	}
}

 

 

TrafficStatActivity.java

package com.nj.demo;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

/**
 * 流量统计
 */
public class TrafficStatActivity extends Activity{

	private TextView mTextViewBaseSendTextView;
	private TextView mTextViewBaseRecvTextView;
	
	private TextView mTextViewTotalSendTextView;
	private TextView mTextViewTotalRecvTextView;
	
	
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        setContentView(R.layout.act_set_trafficstat);
        
        init();
    }
	
	private  void init()
	{
		
		
		View layout1 = findViewById(R.id.trafic_today_tbl);
		mTextViewBaseSendTextView = (TextView) layout1.findViewById(R.id.base_send_trafic);
		mTextViewBaseRecvTextView = (TextView) layout1.findViewById(R.id.base_recv_trafic);
		
		mTextViewTotalSendTextView = (TextView) layout1.findViewById(R.id.total_send_trafic);
		mTextViewTotalRecvTextView = (TextView) layout1.findViewById(R.id.total_recv_trafic);
		
		
		mTextViewBaseSendTextView.setText("14 KB");
		mTextViewBaseRecvTextView.setText("3 KB");
		
		mTextViewTotalSendTextView.setText("14 KB");
		mTextViewTotalRecvTextView.setText("3 KB");
		
	}
}

 

资源下载地址为: http://download.csdn.net/detail/niejing654092427/4500972

 

 

二.自定义PreferenceActivity

 资源下载地址为: http://download.csdn.net/detail/niejing654092427/5209112

 

 


 

你可能感兴趣的:(【Android,UI,样式】)