WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院手机开发Android 开发 Android之设置手机背景 阅读

Android之设置手机背景

 2010-05-08 09:00:00 来源:WEB开发网 闂侀潧妫撮幏锟�闂佸憡鍨电换鎰版儍椤掑倵鍋撳☉娆嶄沪缂傚稄鎷�婵犫拃鍛粶闁靛洤娲ㄩ埀顒佺⊕閵囩偟绱為敓锟�闂侀潧妫撮幏锟�  闂佺ǹ绻楀▍鏇㈠极閻愭娑樷枎閹邦剛娉氶梺鍛婎殔濞层劌鈻撻幋婵愬殫妞ゆ梻鍘х憴锟�
核心提示:设置手机背景很简单,只要重写系统的setWallpaper()方法,Android之设置手机背景,再调用它即可,setWallPaper()方法有两种参数类型:★setWallpaper(Bitmap bitmap)★setWallpaper(InputStream data)现在来一个一个举例:1、setWallpa

设置手机背景很简单,只要重写系统的setWallpaper()方法,再调用它即可。

setWallPaper()方法有两种参数类型:

★setWallpaper(Bitmap bitmap)

★setWallpaper(InputStream data)

现在来一个一个举例:

1、setWallpaper(Bitmap bitmap):

eg: Bitmap bitmap = BitmapFactory.decodeFile(path);

try setWallpaper(bitmap);

} catch (Exception e) // TODO: handle exception @Override

public void setWallpaper(InputStream data) throws IOException {

// TODO Auto-generated method stub

super.setWallpaper(data); 注:path为文件地址。

生成Bitmap对象类型的方法有很多,只要setWallPaper()参数为Bitmap类型即可。

2、setWallpaper(InputStream data)

eg: Resources resources = getBaseContext().getResources();

InputStream is = resources.openRawResource(R.drawable.icon);

try setWallpaper(is);

} catch (Exception e) // TODO: handle exception @Override

public void setWallpaper(InputStream data) throws IOException {

// TODO Auto-generated method stub

super.setWallpaper(data);

}

注:一定要记得在Android Manifest.xml中加入下面语句,声明拥有修改壁纸的权限,不然setWallPaper()方法不起作用

< uses-permission android:name="android.permission.SET_WALLPAPER" / >

手机widget应用程序添加 背景 保持长宽比例

Java代码

1. < FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" >

< ImageView android:layout_width="fill_parent"

1. android:layout_height="fill_parent" android:src="@drawable/back"

1. android:scaleType="fitXY" / >

1. < LinearLayout >your views< /LinearLayout >

1. < /FrameLayout >

Tags:Android 设置 手机

编辑录入:coldstar [复制链接] [打 印]
赞助商链接