如何在Android中将Url图像设置为壁纸

时间:2015-12-29 08:42:34

标签: android

我有一个Android应用程序,它在ImageView中通过活动中的通用图像加载器显示来自url的图像。在该活动中,我首先想要2 TextView将该图片设置为移动设备的壁纸,并将其他TextView设置为来自设备中的网址的下载图片。怎么可能? 这是我的MainActitivity类

    package com.example.home.mywallpaper;

import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;

public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    private TextView setAsWallPaper, save, share;
    private ImageLoader imageLoader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_full_image_view);
        imageView = (ImageView)findViewById(R.id.fullimageView);
        setAsWallPaper = (TextView)findViewById(R.id.setAsWallpaper);
        save = (TextView)findViewById(R.id.save);
        share = (TextView)findViewById(R.id.share);
        imageLoader = ImageLoader.getInstance();
        String url= ">http://www.asihs.org/mistich/images/Strangest-Planess.jpg"
        imageLoader.displayImage(url,imageView);

        setAsWallPaper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

这是我的Application类

    package com.example.home.mywallpaper;

import android.app.Application;

import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

/**
 * Created by home on 12/29/2015.
 */
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // UNIVERSAL IMAGE LOADER SETUP
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheOnDisc(true).cacheInMemory(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .displayer(new FadeInBitmapDisplayer(300)).build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getApplicationContext())
                .defaultDisplayImageOptions(defaultOptions)
                .memoryCache(new WeakMemoryCache())
                .discCacheSize(100 * 1024 * 1024).build();

        ImageLoader.getInstance().init(config);
        // END - UNIVERSAL IMAGE LOADER SETUP
    }
}

0 个答案:

没有答案