天蓬老师2017-04-17 15:48:43
The inheritance relationship is as above
Directly inherit the same parent class and cannot be forced
can be generated using the constructor of Canvas
将ColorDrawable
转成Bitmap
,用 BitmapDrawable
public BitmapDrawable (Bitmap bitmap)
PHP中文网2017-04-17 15:48:43
Can’t.
This is not an Android problem, Java does not allow you to cast an object to an incompatible class
天蓬老师2017-04-17 15:48:43
Refer to Java class object type conversion knowledge, ColorDrawable and BitmapDrawable are in a horizontal relationship, and there is no possibility of forced conversion to each other. The class object conversion mechanism exists between class objects with a parent-child relationship. When forced conversion, only the parent class object can be forced to be converted into a child class object.