Display Method Summary of transparent ImagesMethod 1: Use the drawargb method of canvas.
@ Overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (127,255,); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}
Method 2: Use drawargb of canvas and erasecolor of Bitmap.
Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (127,255,); // use the bitmap method to erase the red color, which is transparent. BM. erasecolor (0xff0000); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}
Method 3: Use the setalpha method of imageview.
Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // color the image. The first parameter is the transparency setting. Canvas CVS = new canvas (BM); cvs. drawargb (255,255,); // create an imageview object. Imageview IMV = new imageview (this); // load the image to an imageview object. IMV. setimagebitmap (BM); // sets the image transparency. IMV. setalpha (127); // display the image on the screen. Setcontentview (IMV );}
Method 4: Use the getpaint (). setcolor method of drawable.
Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create an image. Bitmap Bm = bitmap. createbitmap (20, 20, config. argb_4444); // beautify the image. Canvas CVS = new canvas (BM); cvs. drawargb (255,255,); // create an imageview. Imageview IMV = new imageview (this); // sets the image transparency. The first two values are the transparency values. Bitmapdrawable BD = new bitmapdrawable (BM); Bd. getpaint (). setcolor (0x00ffffff); // load the image to the imageview object. IMV. setimagebitmap (BM); // display the image on the screen. Setcontentview (IMV );}
Note: These four methods have been found for the moment. If I find a new method, I will edit this article.