加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 无法从一堆URL(字符串数组)中设??置壁纸.怎么解决这个?

发布时间:2020-12-15 02:20:05 所属栏目:Java 来源:网络整理
导读:我目前正在创建一个应用程序,以网格布局(recyclerView)显示来自Web的图像.选择一个图像时,将打开另一个活动并以全屏显示相同的图像(就像图库一样).我正在使用Glide库来达到这个目的.在这个活动中,我实现了一个底部工具栏,其中包含两个项目“set wallpaper”
我目前正在创建一个应用程序,以网格布局(recyclerView)显示来自Web的图像.选择一个图像时,将打开另一个活动并以全屏显示相同的图像(就像图库一样).我正在使用Glide库来达到这个目的.在这个活动中,我实现了一个底部工具栏,其中包含两个项目“set wallpaper”和“Download”.我已经编写了设置壁纸的代码,但它似乎不起作用,应用程序也不会崩溃.我附加了网格视图的图像和其他活动(代码和全屏图像)
我需要帮助将全屏图像设置为墙纸,这适用于网格视图中的所有图像.
图像: http://imgur.com/a/LSbX0

代码:

public class SecondActivity extends Activity {

    BottomBar bottomBar;

    public static final String image = "SecondActivity.LIST_ITEMS";
    ImageView selectedImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);


        bottomBar = (BottomBar)findViewById(R.id.bottom_navbar);

        selectedImage = (ImageView) findViewById(R.id.selectedImage); // init a ImageView

        final ListItem listItem = getIntent().getParcelableExtra(image);

        Glide.with(this).asBitmap().load(listItem.getImgurl()).into((ImageView)findViewById(R.id.selectedImage));



        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
           public void onTabSelected(@IdRes int tabId) {
               if(tabId == R.id.setwallpaper){


                   Glide.with(getApplicationContext()).asBitmap().load(selectedImage).into(new SimpleTarget<Bitmap>(){

                        @Override
                        public void onResourceReady(Bitmap resource,Transition<? super Bitmap> transition) {
                            try {
                                WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);
                                Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG).show();


                            } catch (IOException e) {
                                e.printStackTrace();
                                Toast.makeText(getApplicationContext(),"Failed",Toast.LENGTH_LONG).show();
                            }
                        }



                   });
               }

               if(tabId == R.id.download){





               }

            }
        });



    }
}

日志:

08-27 23:28:08.881 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(22)
08-27 23:28:08.884 5247-5403/quote.quotemania E/GlideExecutor: Request threw uncaught throwable
    com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: android.widget.ImageView{b8534d9 V.ED..... ......I. 0,0-0,0 #7f0f00a7 app:id/selectedImage}
      at com.bumptech.glide.Registry.getModelLoaders(Registry.java:227)
      at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:179)
      at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:197)
      at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:41)
      at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282)
      at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:249)
      at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:761)
      at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)
08-27 23:28:08.888 5247-5273/quote.quotemania V/FA: Using measurement service
08-27 23:28:08.888 5247-5273/quote.quotemania V/FA: Connection attempt already in progress
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Using measurement service
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Connection attempt already in progress
08-27 23:28:08.889 5247-5273/quote.quotemania V/FA: Activity resumed,time: 3119251
08-27 23:28:08.890 5247-5273/quote.quotemania D/FA: Connected to remote service
08-27 23:28:08.890 5247-5273/quote.quotemania V/FA: Processing queued up service tasks: 3
08-27 23:28:08.891 5247-5247/quote.quotemania W/Glide: Load failed for android.widget.ImageView{b8534d9 V.ED..... ......I. 0,0 #7f0f00a7 app:id/selectedImage} with size [-2147483648x-2147483648]
                                                       class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-27 23:28:08.891 5247-5247/quote.quotemania E/Glide: class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-27 23:28:08.900 2431-5278/com.google.android.gms V/FA-SVC: Logging event: origin=auto,name=_e,params=Bundle[mParcelledData.dataSize=132]
08-27 23:28:08.906 2431-5278/com.google.android.gms V/FA-SVC: Saving event,name,data size: _e,68
08-27 23:28:08.906 2431-5278/com.google.android.gms V/FA-SVC: Event recorded: Event{appId='quote.quotemania',name='_e',params=Bundle[{_o=auto,_et=8878,_sc=BrowseQuotes,_si=-5888889340355970828}]}
08-27 23:28:08.909 2431-5278/com.google.android.gms V/FA-SVC: Background event processing time,ms: 9
08-27 23:28:08.938 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.955 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.967 1298-1340/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
08-27 23:28:08.984 5247-5247/quote.quotemania W/View: requestLayout() improperly called by android.widget.TextView{8a7a611 V.ED..... ......ID 294,133-294,196 #7f0f00ae app:id/bb_bottom_bar_title} during layout: running second layout pass
08-27 23:28:08.984 5247-5247/quote.quotemania W/View: requestLayout() improperly called by android.widget.TextView{6211376 V.ED..... ......ID 294,140-294,196 #7f0f00ae app:id/bb_bottom_bar_title} during layout: running second layout pass
08-27 23:28:09.127 1577-1600/system_process I/ActivityManager: Displayed quote.quotemania/.SecondActivity: +279ms
08-27 23:28:13.903 5247-5273/quote.quotemania V/FA: Inactivity,disconnecting from the service
08-27 23:28:19.770 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(11)
08-27 23:28:21.668 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(43)
08-27 23:28:21.732 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(1)
08-27 23:28:24.034 1309-1329/? D/AudioFlinger: mixer(0xa8083940) throttle end: throttle time(1)

Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="quote.quotemania">

<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"></activity>
    <activity android:name=".BrowseQuotes"></activity>
    <activity android:name=".splash_screen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SecondActivity"></activity>
</application>

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:design="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/framelayout"
    android:layout_above="@+id/bottom_navbar" >


<ImageView
    android:id="@+id/selectedImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY" />

</FrameLayout>

<com.roughike.bottombar.BottomBar
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/bottom_navbar"
    android:layout_alignParentBottom="true"
    app:bb_tabXmlResource="@xml/bottombar_tabs"
    android:background="#263f40"
    app:bb_inActiveTabColor="#fff"
    app:bb_activeTabColor="#fff"
    >

</com.roughike.bottombar.BottomBar>

</RelativeLayout>

解决方法

解决方案:

而不是工具栏,使用按钮!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读