Android編程之手機(jī)壁紙WallPaper設(shè)置方法示例
本文實(shí)例講述了Android編程之手機(jī)壁紙WallPaper設(shè)置方法。分享給大家供大家參考,具體如下:
/** * Andorid設(shè)置手機(jī)屏幕的壁紙 * * @description: * @author ldm * @date 2016-5-4 下午3:08:56 */ public class SetWallpaperActivity extends Activity { // WallpaperManager類(lèi):系統(tǒng)壁紙管理。通過(guò)它可以獲得當(dāng)前壁紙以及設(shè)置指定圖片作為系統(tǒng)壁紙。 private WallpaperManager wallpaperManager; // 壁紙對(duì)應(yīng)的Drawable private Drawable wallpaperDrawable; // 展示樣式的ImageView private ImageView imageView; // 隨機(jī)生成圖片的顏色 Button private Button randomize; // 設(shè)置壁紙 private Button setWallpaper; // 暫定的一些顏色值 final static private int[] mColors = { Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN, Color.YELLOW, Color.WHITE }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.set_wallpaper); // 初始化WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); wallpaperDrawable = wallpaperManager.getDrawable();// 獲得當(dāng)前系統(tǒng)的壁紙 initViews(); initListeners(); } private void initListeners() { randomize.setOnClickListener(new OnClickListener() { public void onClick(View view) { int mColor = (int) Math.floor(Math.random() * mColors.length); // 給當(dāng)前系統(tǒng)壁紙?jiān)O(shè)置顏色 wallpaperDrawable.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);// 取兩層繪制交集 imageView.setImageDrawable(wallpaperDrawable); // imageView.invalidate(); } }); setWallpaper.setOnClickListener(new OnClickListener() { public void onClick(View view) { try { // 設(shè)置壁紙 wallpaperManager.setBitmap(imageView.getDrawingCache()); finish(); } catch (IOException e) { e.printStackTrace(); } } }); } private void initViews() { imageView = (ImageView) findViewById(R.id.imageview); imageView.setDrawingCacheEnabled(true); imageView.setImageDrawable(wallpaperDrawable); randomize = (Button) findViewById(R.id.randomize); setWallpaper = (Button) findViewById(R.id.setwallpaper); } }
布局文件:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageview" /> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="match_parent"> <Button android:id="@+id/randomize" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/randomize" android:layout_gravity="bottom" /> <Button android:id="@+id/setwallpaper" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/set_wallpaper" android:layout_gravity="bottom" /> </LinearLayout> </FrameLayout>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android圖形與圖像處理技巧總結(jié)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android自定義動(dòng)態(tài)壁紙開(kāi)發(fā)詳解
- Android使用線程更換壁紙
- Android-Service實(shí)現(xiàn)手機(jī)壁紙自動(dòng)更換
- Android HttpURLConnection下載網(wǎng)絡(luò)圖片設(shè)置系統(tǒng)壁紙
- Android仿百度壁紙客戶(hù)端之搭建主框架(一)
- Android編程之動(dòng)態(tài)壁紙實(shí)例分析
- Android實(shí)現(xiàn)手機(jī)壁紙改變的方法
- Android開(kāi)發(fā)學(xué)習(xí)之WallPaper設(shè)置壁紙?jiān)敿?xì)介紹與實(shí)例
- android動(dòng)態(tài)壁紙調(diào)用的簡(jiǎn)單實(shí)例
- Android動(dòng)態(tài)時(shí)鐘壁紙開(kāi)發(fā)
相關(guān)文章
Android實(shí)現(xiàn)編程修改手機(jī)靜態(tài)IP的方法
這篇文章主要介紹了Android實(shí)現(xiàn)編程修改手機(jī)靜態(tài)IP的方法,涉及Android編程實(shí)現(xiàn)對(duì)系統(tǒng)底層信息修改的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Android 軟鍵盤(pán)狀態(tài)并隱藏輸入法的實(shí)例
這篇文章主要介紹了Android 軟鍵盤(pán)狀態(tài)并隱藏輸入法的實(shí)例的相關(guān)資料,這里提供實(shí)例實(shí)現(xiàn)軟鍵盤(pán)切換并隱藏輸入法的鍵盤(pán),需要的朋友可以參考下2017-09-09實(shí)時(shí)獲取股票數(shù)據(jù)的android app應(yīng)用程序源碼分享
本文我們分享一個(gè)實(shí)時(shí)獲取股票數(shù)據(jù)的android app應(yīng)用程序源碼分享,可以作為學(xué)習(xí)使用,本文貼出部分重要代碼,需要的朋友可以參考下本文2015-09-09Android應(yīng)用關(guān)閉的情況以及識(shí)別方法詳解
對(duì)于現(xiàn)在的安卓手機(jī)而言,很多功能都是在逐步完善的,這篇文章主要給大家介紹了關(guān)于Android應(yīng)用關(guān)閉的情況以及識(shí)別的相關(guān)資料,文章通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06ubuntu用wifi連接android調(diào)試程序的步驟
這篇文章主要介紹了ubuntu用wifi連接android調(diào)試程序的步驟,需要的朋友可以參考下2014-02-02Android handle-message的發(fā)送與處理案例詳解
這篇文章主要介紹了Android handle-message的發(fā)送與處理案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08Android之rk3588?開(kāi)發(fā)環(huán)境準(zhǔn)備及問(wèn)題解決方法
這篇文章主要介紹了Android中的rk3588?開(kāi)發(fā)環(huán)境準(zhǔn)備,本文給大家分享遇到的問(wèn)題及解決方法,本文給大家講解的非常詳細(xì)對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11Android回調(diào)與觀察者模式的實(shí)現(xiàn)原理
這篇文章主要為大家詳細(xì)介紹了Android回調(diào)與觀察者模式的實(shí)現(xiàn)原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04Android?MaterialAlertDialogBuilder修改按鈕屬性
這篇文章主要介紹了Android?MaterialAlertDialogBuilder修改按鈕屬性實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11