Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use WallPaper to set wallpaper in Android

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use WallPaper to set wallpaper in Android". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use WallPaper to set up wallpaper in Android.

The specific code is as follows:

Public class SetWallpaperActivity extends Activity {/ / WallpaperManager class: system wallpaper management. Through it, you can get the current wallpaper and set the specified picture as the system wallpaper. Private WallpaperManager wallpaperManager; / / wallpaper corresponding Drawable private Drawable wallpaperDrawable; / / display style ImageView private ImageView imageView; / / randomly generated picture color Button private Button randomize; / / set wallpaper private Button setWallpaper; / / tentative color values 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); / / initialize WallpaperManager wallpaperManager = WallpaperManager.getInstance (this); wallpaperDrawable = wallpaperManager.getDrawable (); / / get the wallpaper initViews () of the current system; initListeners () } private void initListeners () {randomize.setOnClickListener (new OnClickListener () {public void onClick (View view) {int mColor = (int) Math.floor (Math.random () * mColors.length)); / / set the color wallpaperDrawable.setColorFilter (mColors [mColor], PorterDuff.Mode.MULTIPLY) to the current system wallpaper; / / draw intersection imageView.setImageDrawable (wallpaperDrawable) with two layers / / imageView.invalidate ();}}); setWallpaper.setOnClickListener (new OnClickListener () {public void onClick (View view) {try {/ / set wallpaper 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);}}

Layout file:

At this point, I believe you have a deeper understanding of "how to use WallPaper to set up wallpaper in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report