इस FrameLayout
ले लो जो छाया खींचता है और this gradient drawable xml:
public class DrawShadowFrameLayout extends FrameLayout {
private Drawable mShadowDrawable;
private final int mShadowElevation = 8;
private int mWidth;
private int mHeight;
private boolean mShadowVisible = true;
public DrawShadowFrameLayout(Context context) {
this(context, null, 0);
init();
}
public DrawShadowFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
init();
}
public DrawShadowFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mShadowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.shadow);
if (mShadowDrawable != null) {
mShadowDrawable.setCallback(this);
}
setWillNotDraw(!mShadowVisible);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = w;
mHeight = h;
updateShadowBounds();
}
private void updateShadowBounds() {
if (mShadowDrawable != null) {
mShadowDrawable.setBounds(0, 0, mWidth, mShadowElevation);
}
ViewCompat.postInvalidateOnAnimation(this);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (mShadowDrawable != null && mShadowVisible) {
getBackground().setBounds(0, mShadowDrawable.getBounds().bottom, mWidth, mHeight);
mShadowDrawable.draw(canvas);
}
}
public void setShadowVisible(boolean shadowVisible) {
setWillNotDraw(!mShadowVisible);
updateShadowBounds();
}
int getShadowElevation() {
return mShadowVisible ? mShadowElevation : 0;
}
}
लपेटें अपने BottomNavigationView
इस इस लेआउट की तरह अंदर:
<DrawShadowFrameLayout>
<BottomNavigationView />
</DrawShadowFrameLayout>
दुर्भाग्य से, देशी छाया देखने के तहत तैयार की है, हम इस नकल करने के लिए है ऊपर की ओर अपने आप को शैडो।
DrawShadowFrameLayout
के लिए भी android:elevation="8dp"
जोड़ने के लिए मत भूलना।
Another approach is extendingBottomNavigationView
और ऐसा करने के लिए draw()
ओवरराइड करना। इससे आपको अपने दृश्य पदानुक्रम में FrameLayout
खोने में मदद मिलेगी।
स्रोत
2016-11-01 09:59:24
यह सच छाया प्रतीत होता है कि केवल जब पृष्ठभूमि सफेद है। यह तो बेवकूफी है। कोई विचार क्यों? – WindRider
मैं मानता हूं कि यह बहुत निराश है और इसका कोई संकेत नहीं है। – luksha
हाय @ लुकशा मैं वही करता हूं जो आप कहते हैं, लेकिन मैं अभी तक काम नहीं कर रहा हूं :(आश्चर्य की बात है कि, यदि मैं स्क्रीन के शीर्ष पर BottomNavigationBar डालता हूं, तो यह नेविगेशन व्यू की निचली सीमा को बढ़ाता है। हालांकि, जब मैं इसे नीचे के नीचे रखता हूं स्क्रीन, ऊंचाई काम करना बंद कर देता है –