【问题标题】:Set mywallpaper in android after pressed button按下按钮后在android中设置mywallpaper
【发布时间】:2014-07-13 20:49:12
【问题描述】:

我制作了自己的壁纸,但当用户单击“设置壁纸”按钮时,我不知道如何设置它

我写道:

<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />

但不是代码,我需要你的帮助。

【问题讨论】:

    标签: android wallpaper


    【解决方案1】:

    这是我的解决方案 .... 使用 Intent 启动 MyWallPaperService

    Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
                                intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                                    new ComponentName(getApplicationContext(), MyWallpaperService.class));
                                startActivity(intent);
    

    谢谢!

    【讨论】:

      【解决方案2】:

      你可以改变一个Activity的背景:

      • Activity 布局中,将根View(通常为LinearLayourRelativeLayout)设置为android:background="@drawable/yourdrawable"

      • 以编程方式:

        LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);
        ll.setBackgroundDrawable(...)
        
      • 或为您的应用添加主题或Activity

      在您的情况下,您有兴趣以编程方式更改它,因此您需要使用第二个选项。您需要在按钮中添加onClickListener 并在里面更改背景,如下所示:

          myButton.setOnClickListener(new OnClickListener() {
      
              @Override
              public void onClick(View arg0) {
                  LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);
                  ll.setBackgroundDrawable(...)
              }
          });
      

      顺便说一句,要更改您的活动背景,您不需要使用权限

      <uses-permission android:name="android.permission.SET_WALLPAPER" />
      <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
      

      你有类似的问题:

      How to programmatically change the background image of an Android Activity

      Change Layout-background on click programmatically

      Android: Changing Background-Color of the Activity (Main View)

      How to set background color of an Activity to white programmatically?

      【讨论】:

      • 但我在壁纸中有一个带有图像和文字的课程
      • 但是您想为您的应用或系统设置壁纸?
      • 在我的应用程序(wallpapercustom)中,我想在活动中放置一个按钮,上面写着“SET WALLPAPER”,这将改变我手机的壁纸
      • @EliasTimMamaniCanaza 我已经编辑了我的答案,我以为你想更改手机壁纸,而不是你的活动背景。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多