0

我希望用户在单击所选图像以将图像设置为墙纸或将其保存到他们的 SD 卡后获得该选项。

这是我第一次这样做,所以我需要一些指导。我已经查看了与此类似的其他问题,但每个人都使用与我设置显示图像的方法不同的方法。

在此先感谢,这是代码:

显示图像的适配器视图在:

package com.question;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class AdapterViewADV extends BaseAdapter {
private Context mContext;


public Integer[] mThumbIds = {
    R.drawable.Image1,
    R.drawable.Image2,
    R.drawable.Image3,
    R.drawable.Image4,
    R.drawable.Image5,
    R.drawable.Image6

};


public AdapterViewADV(Context c){
mContext = c;
}

@Override
public int getCount() {
return mThumbIds.length;
}

@Override
public Object getItem(int position) {
return mThumbIds[position];
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
if(convertView == null){
   imageView = new ImageView(mContext);imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
   imageView.setLayoutParams(new GridView.LayoutParams(NO_SELECTION, NO_SELECTION));
   convertView = imageView;
}else{
    imageView = (ImageView)convertView;
}
imageView.setImageResource(mThumbIds[position]);

return convertView;


       } 
}

显示图像的类:

package com.question;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

public class Displayimagesin extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_battlefield4);

    GridView gridView = (GridView) findViewById(R.id.grid_view);

    // Instance of ImageAdapter Class
    gridView.setAdapter(new AdapterViewADV(this));

    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            Toast.makeText(Displayimagesin.this, "Wallpaper set",
                    Toast.LENGTH_SHORT).show();

        }
    });
}

}
4

2 回答 2

1

尝试使用 WallpaperManager 设置壁纸

        WallpaperManager myWallpaperManager=WallpaperManager.getInstance(getApplicationContext());            

            myWallpaperManager.setResource(mThumbIds[curruntPosition]);
于 2013-08-30T11:05:41.380 回答
1

通过调用设置壁纸WallpaperManager。获取对您的图像的引用Bitmap。像这样的东西

WallpaperManager wm=WallpaperManager.getInstance(this);
wm.setBitmap(bitmap);

并在清单文件中添加权限

android.permission.SET_WALLPAPER

希望能帮助到你。

于 2013-08-30T11:06:24.400 回答