<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tony.skindemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="com.tony.skindemo.SkinDemoActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:textColor="#ff00ff" android:text="程序皮肤更换" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <RadioGroup android:id="@+id/skin_options" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioButton android:layout_weight="1" android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="风格1" /> <RadioButton android:layout_weight="1" android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="风格2" /> <RadioButton android:layout_weight="1" android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="风格3" /> <RadioButton android:layout_weight="1" android:id="@+id/radioButton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="风格4" /> <RadioButton android:layout_weight="1" android:id="@+id/radioButton5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="风格5" /> </RadioGroup> </LinearLayout>
package com.tony.skindemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class SkinDemoActivity extends Activity {
private SkinSettingManager mSettingManager;
private RadioButton radioButton1;
private RadioButton radioButton2;
private RadioButton radioButton3;
private RadioButton radioButton4;
private RadioButton radioButton5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 取消标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 完成窗体的全屏显示 // 取消掉状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
// 初始化皮肤
mSettingManager = new SkinSettingManager(this);
mSettingManager.initSkins();
//通过单选按钮设置皮肤(可自定义更换的方式,如导航栏,也可以加上预览功能,此处不再实现)
radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
radioButton3 = (RadioButton) findViewById(R.id.radioButton3);
radioButton4 = (RadioButton) findViewById(R.id.radioButton4);
radioButton5 = (RadioButton) findViewById(R.id.radioButton5);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.skin_options);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radioButton1:
mSettingManager.changeSkin(1);
break;
case R.id.radioButton2:
mSettingManager.changeSkin(2);
break;
case R.id.radioButton3:
mSettingManager.changeSkin(3);
break;
case R.id.radioButton4:
mSettingManager.changeSkin(4);
break;
case R.id.radioButton5:
mSettingManager.changeSkin(5);
break;
default:
break;
}
}
});
}
// 这里为了简单实现,实现换肤
public boolean onTouchEvent(MotionEvent event) {
mSettingManager.toggleSkins();
return super.onTouchEvent(event);
}
}
import android.app.Activity;
import android.content.SharedPreferences;
/**
* 皮肤管理器
* @author tony
*
*/
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());
}
/**
* 随即切换一个背景皮肤
*/
public void changeSkin(int id) {
setSkinType(id);
mActivity.getWindow().setBackgroundDrawable(null);
try {
mActivity.getWindow().setBackgroundDrawableResource(getCurrentSkinRes());
} catch (Throwable e) {
e.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有