首页>代码>android皮肤更换>/SkinDemo/src/com/tutor/skindemo/SkinSettingManager.java
package com.tutor.skindemo;


import android.app.Activity;
import android.content.SharedPreferences;

/**
 * PadQzone皮肤管理器
 * @author frankiewei
 *
 */
public class SkinSettingManager {


	public final static String SKIN_PREF = "skinSetting";
	
	public SharedPreferences skinSettingPreference;
	
	private int[] skinResources = { R.drawable.default_wallpaper,
			R.drawable.wallpaper_c,R.drawable.wallpaper_d,R.drawable.wallpaper_f,
			R.drawable.wallpaper_g
	};
	
	private Activity mActivity;
	
	
	public SkinSettingManager(Activity activity) {
		this.mActivity = activity;	
		skinSettingPreference = mActivity.getSharedPreferences(SKIN_PREF, 3);
	}
	
	/**
	 * 获取当前程序的皮肤序号
	 * 
	 * @return
	 */
	public int getSkinType() {
		String key = "skin_type";
		return skinSettingPreference.getInt(key, 0);
	}

	/**
	 * 把皮肤序号写到全局设置里去
	 * 
	 * @param j
	 */
	public void setSkinType(int j) {
		SharedPreferences.Editor editor = skinSettingPreference.edit();
		String key  = "skin_type";
		
		editor.putInt(key, j);
		editor.commit();
	}
	
	/**
	 * 获取当前皮肤的背景图资源id
	 * 
	 * @return
	 */
	public int getCurrentSkinRes() {
		int skinLen = skinResources.length;
		int getSkinLen = getSkinType();
		if(getSkinLen >= skinLen){
			getSkinLen = 0;
		}
		
		return skinResources[getSkinLen];
	}
	
	/**
	 * 用于导航栏皮肤按钮切换皮肤
	 */
	public void toggleSkins(){
		
		int skinType = getSkinType();
		if(skinType == skinResources.length - 1){
			skinType = 0;
		}else{			
			skinType ++;
		}
		setSkinType(skinType);
		mActivity.getWindow().setBackgroundDrawable(null);
		try {
			mActivity.getWindow().setBackgroundDrawableResource(getCurrentSkinRes());
		} catch (Throwable e) {
			e.printStackTrace();

		}
		
		
	}
		
	/**
	 * 用于初始化皮肤
	 */
	public void initSkins(){	
		mActivity.getWindow().setBackgroundDrawableResource(getCurrentSkinRes());
	}

}
最近下载更多
511076827  LV33 2022年4月10日
我想要两个西柚  LV2 2021年7月1日
homnpg  LV8 2021年4月10日
wlw123  LV6 2020年12月28日
11111222  LV8 2019年10月12日
王闹闹  LV2 2019年6月24日
史梦瑶521  LV4 2019年6月20日
秀儿1234567  LV2 2019年5月30日
wangshihua  LV19 2019年5月7日
mahw9860  LV12 2019年2月26日
最近浏览更多
妖刀飞姬杯  LV2 2023年6月9日
uni-code_0123  LV1 2022年11月16日
四季夏目  LV7 2022年6月19日
张恺祺  LV6 2022年5月21日
bingpine  LV6 2022年5月16日
511076827  LV33 2022年4月10日
969334274  LV1 2021年12月14日
zhjfirst  LV1 2021年10月23日
刘亦宸 2021年7月16日
暂无贡献等级
_nrxsh  LV12 2021年7月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友