【问题标题】:How to set android wallpaper如何设置安卓壁纸
【发布时间】:2010-08-09 15:51:33
【问题描述】:

我想知道是否有人可以提供帮助。我想创建一个简单的壁纸测试应用程序。我尝试了一些没有成功的事情。最终,我开始使用画廊代码并取得了一些成就。但是......我不确定如何将壁纸功能附加到画廊。我对这一切都很陌生(我只有几个月的时间来学习使用 eclipse 的 Droid 应用程序)是否有地方可以找到完整的 Java 编码以及可能用于工作壁纸的 XML 文件?我无法从头开始构建,但我正在更好地阅读创建按钮等的源代码。

另一种选择是如何将另存为墙纸功能插入我拥有的工作画廊?我假设我可以设置长按功能,但我也不知道该怎么做。我确实有一个创建长按的教程,但我不确定相应的 Java 设置是否正确。

任何帮助将不胜感激。请记住,我对 Java 和 Android 编码都是新手。换句话说,请尽可能简单。或者,如果有人有一个简单的壁纸应用,并且他们不介意分享源代码……那将非常有帮助。

【问题讨论】:

标签: android gallery wallpaper


【解决方案1】:
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
    bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
    System.out.println("Hi I am try to open Bit map");
    wallpaperManager = WallpaperManager.getInstance(this);
    wallpaperDrawable = wallpaperManager.getDrawable();
    wallpaperManager.setBitmap(useThisBitmap);

.................................................. .. 如果你有图像 URI,那么使用这个

wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);

........如果有任何问题,请告诉我。

【讨论】:

    【解决方案2】:

    如果您有图片网址,请使用

    WallpaperManager wpm = WallpaperManager.getInstance(context);
    InputStream ins = new URL("absolute/path/of/image").openStream();
    wpm.setStream(ins);
    

    如果您有图像 URI,则使用

    WallpaperManager wpm = WallpaperManager.getInstance(context);
    wpm.setResource(Uri.of.image);
    

    【讨论】:

      【解决方案3】:

      如果您想使用壁纸作为应用的背景,则必须使用壁纸主题并调用 Intent.Action_Set_Wallpaper 来选择壁纸。

      public void onCreate(Bundle savedInstanceState) {
      
       Activity.this.setTheme(android.R.style.Theme_Wallpaper);
      
      super.onCreate(savedInstanceState);
      setContentView(/*some layout*/);
      }
      

      //点击按钮

      Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
      startActivity(Intent.createChooser(intent, "Select Wallpaper"));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多