您好,登錄后才能下訂單哦!
小編給大家分享一下Android怎么使用線程更換壁紙,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
先看效果:
一個線程30行代碼搞定:
public class MainActivity extends Activity { Thread thread = new Thread(){ @Override public void run() { for (;current<5;){ if (current >= 3) { current = 0; } //使用資源文件 當然你也可以使用其他圖片bitmap BitmapDrawable bitmap = (BitmapDrawable) getResources().getDrawable(wallpapers[current++]); wallpaperManager = WallpaperManager.getInstance(MainActivity.this); try { wallpaperManager.setBitmap(bitmap.getBitmap()); } catch (IOException e) { e.printStackTrace(); } } } }; int[] wallpapers = new int[]{ R.drawable.background1, R.drawable.background2, R.drawable.background3 }; WallpaperManager wallpaperManager; int current = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); thread.start(); } }
就這么簡單 對了別忘了在mainfest里加權(quán)限
<!--授予用戶修改壁紙權(quán)限--> <uses-permission android:name="android.permission.SET_WALLPAPER" />
Android是一種基于Linux內(nèi)核的自由及開放源代碼的操作系統(tǒng),主要使用于移動設(shè)備,如智能手機和平板電腦,由美國Google公司和開放手機聯(lián)盟領(lǐng)導(dǎo)及開發(fā)。
以上是“Android怎么使用線程更換壁紙”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。