Android,View转换bitmap,bitmap转换drawable

Android View转换Bitmap,Bitmap转换Drawable

 

  //测试设置bitmap
            View view1 = ViewGroup.inflate(context, R.layout.drawable_icon, null);
            TextView textView1 = view1.findViewById(R.id.tv_text);
            TextView textView2 = view1.findViewById(R.id.tv_text2);
            textView1.setText(data.getName());
            textView2.setText(data.getTradeDate());

            //判断显示那种颜色
            if (data.isNow()){//显示红色
                textView1.setTextColor(context.getResources().getColor(R.color.RED));
                textView2.setTextColor(context.getResources().getColor(R.color.RED));
            }else{//显示黑色
                textView2.setTextColor(context.getResources().getColor(R.color.black));
                textView2.setTextColor(context.getResources().getColor(R.color.black));
            }


            Bitmap bitmap = DateUtil.convertViewToBitmap(view1);
            Drawable drawable=new BitmapDrawable(bitmap);

 

真实可用,以此记录

posted @ 2019-01-07 15:55  丁先森  阅读(2559)  评论(0编辑  收藏  举报