Android編程之手機壁紙WallPaper設(shè)置方法示例
本文實例講述了Android編程之手機壁紙WallPaper設(shè)置方法。分享給大家供大家參考,具體如下:
/** * Andorid設(shè)置手機屏幕的壁紙 * * @description: * @author ldm * @date 2016-5-4 下午3:08:56 */ public class SetWallpaperActivity extends Activity { // WallpaperManager類:系統(tǒng)壁紙管理。通過它可以獲得當前壁紙以及設(shè)置指定圖片作為系統(tǒng)壁紙。 private WallpaperManager wallpaperManager; // 壁紙對應(yīng)的Drawable private Drawable wallpaperDrawable; // 展示樣式的ImageView private ImageView imageView; // 隨機生成圖片的顏色 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();// 獲得當前系統(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); // 給當前系統(tǒng)壁紙設(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)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android自定義動態(tài)壁紙開發(fā)詳解
- Android使用線程更換壁紙
- Android-Service實現(xiàn)手機壁紙自動更換
- Android HttpURLConnection下載網(wǎng)絡(luò)圖片設(shè)置系統(tǒng)壁紙
- Android仿百度壁紙客戶端之搭建主框架(一)
- Android編程之動態(tài)壁紙實例分析
- Android實現(xiàn)手機壁紙改變的方法
- Android開發(fā)學(xué)習(xí)之WallPaper設(shè)置壁紙詳細介紹與實例
- android動態(tài)壁紙調(diào)用的簡單實例
- Android動態(tài)時鐘壁紙開發(fā)
相關(guān)文章
Android實現(xiàn)編程修改手機靜態(tài)IP的方法
這篇文章主要介紹了Android實現(xiàn)編程修改手機靜態(tài)IP的方法,涉及Android編程實現(xiàn)對系統(tǒng)底層信息修改的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10實時獲取股票數(shù)據(jù)的android app應(yīng)用程序源碼分享
本文我們分享一個實時獲取股票數(shù)據(jù)的android app應(yīng)用程序源碼分享,可以作為學(xué)習(xí)使用,本文貼出部分重要代碼,需要的朋友可以參考下本文2015-09-09Android應(yīng)用關(guān)閉的情況以及識別方法詳解
對于現(xiàn)在的安卓手機而言,很多功能都是在逐步完善的,這篇文章主要給大家介紹了關(guān)于Android應(yīng)用關(guān)閉的情況以及識別的相關(guān)資料,文章通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-06-06ubuntu用wifi連接android調(diào)試程序的步驟
這篇文章主要介紹了ubuntu用wifi連接android調(diào)試程序的步驟,需要的朋友可以參考下2014-02-02Android handle-message的發(fā)送與處理案例詳解
這篇文章主要介紹了Android handle-message的發(fā)送與處理案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08Android之rk3588?開發(fā)環(huán)境準備及問題解決方法
這篇文章主要介紹了Android中的rk3588?開發(fā)環(huán)境準備,本文給大家分享遇到的問題及解決方法,本文給大家講解的非常詳細對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-11-11Android回調(diào)與觀察者模式的實現(xiàn)原理
這篇文章主要為大家詳細介紹了Android回調(diào)與觀察者模式的實現(xiàn)原理,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04Android?MaterialAlertDialogBuilder修改按鈕屬性
這篇文章主要介紹了Android?MaterialAlertDialogBuilder修改按鈕屬性實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11