There is no normal method, but it can still be achieved through Java reflection. However, even if it is implemented, the effect ofelevationwill not be produced. Take a look at the Android source code first:
public class PopupWindow { ... ... private View mBackgroundView; public void setElevation(float elevation) { mElevation = elevation; } private void preparePopup(WindowManager.LayoutParams p) { ... ... // The background owner should be elevated so that it casts a shadow. mBackgroundView.setElevation(mElevation); } }
From the above code, we can know that as long asmBackgroundView, 然后调用ViewCompat.setElevation(View, float)is obtained through reflection, the work is completed. However, since the lower version does not have theelevationattribute, the above calls are only processed for compatibility to ensure that they do not crash.
There is no normal method, but it can still be achieved through Java reflection. However, even if it is implemented, the effect ofelevationwill not be produced. Take a look at the Android source code first:
From the above code, we can know that as long as
mBackgroundView
, 然后调用ViewCompat.setElevation(View, float)
is obtained through reflection, the work is completed. However, since the lower version does not have theelevationattribute, the above calls are only processed for compatibility to ensure that they do not crash.Another way of thinking:
High version by settingelevation
lower version passed
Background Drawable
p.s. Why not just use them all
Background Drawable