读取路径下的图片文件,设置为app背景图

2018-05-11  本文已影响0人  跟我去北方吧
/**
     * 动态设定认证背景图
     */
    private void initBackground() {
        File file = new File(PIC_PATH);
        if(file.exists()){
            Log.e(TAG,"图片:"+PIC_PATH+"存在!切换背景图!");
            try {
                main_background = (FrameLayout) findViewById(R.id.main_background);
                BitmapDrawable drawable = new BitmapDrawable(BitmapFactory.decodeFile(PIC_PATH));
                main_background.setBackground(drawable);
            } catch (Exception e) {
                Log.e(TAG, e.toString());
            }
        }else{
            Log.e(TAG,"图片:"+PIC_PATH+"不存在!使用原背景图!");
        }

    }
上一篇 下一篇

猜你喜欢

热点阅读