AppBarLayoutडिज़ाइन समर्थन लाइब्रेरी में विजेट का उपयोग करते समय, टूलबार के नीचे एक छाया दिखाई देती है। मैं उस छाया को कैसे हटा सकता हूं?
AppBarLayoutडिज़ाइन समर्थन लाइब्रेरी में विजेट का उपयोग करते समय, टूलबार के नीचे एक छाया दिखाई देती है। मैं उस छाया को कैसे हटा सकता हूं?
जवाबों:
बस app:elevation="0dp""AppBarLayout" छाया का उपयोग करने के लिए अंदर का उपयोग करें । इसने हमेशा मेरे लिए काम किया है। आशा है कि यह आप के लिए काम करता है।
setOutlineProvider
यह समस्या केवल तब होती है जब एपीआई संस्करण> = 21, यदि आप ऊँचाई नहीं बदलना चाहते हैं, तो आप इसका उपयोग कर सकते हैं:
appBar.setOutlineProvider(null);
एपीआई संस्करण की जांच करने के लिए याद रखें
संपादित करें:
ब्लो का सोर्स कोड है setOutlineProvider।
/**
* Sets the {@link ViewOutlineProvider} of the view, which generates the Outline that defines
* the shape of the shadow it casts, and enables outline clipping.
* <p>
* The default ViewOutlineProvider, {@link ViewOutlineProvider#BACKGROUND}, queries the Outline
* from the View's background drawable, via {@link Drawable#getOutline(Outline)}. Changing the
* outline provider with this method allows this behavior to be overridden.
* <p>
* If the ViewOutlineProvider is null, if querying it for an outline returns false,
* or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.
* <p>
* Only outlines that return true from {@link Outline#canClip()} may be used for clipping.
*
* @see #setClipToOutline(boolean)
* @see #getClipToOutline()
* @see #getOutlineProvider()
*/
public void setOutlineProvider(ViewOutlineProvider provider) {
mOutlineProvider = provider;
invalidateOutline();
}
ऐसा कहा जाता है कि If the ViewOutlineProvider is null, if querying it for an outline returns false, or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.
इसलिए, यदि आप छाया हटाना चाहते हैं, तो आप सेटिंग के बजाय इस विधि का बेहतर उपयोग करेंगे app:elevation। ऐसा लगता है कि छाया को हटाने के लिए ऊंचाई को बदलना एक तरह का दुष्प्रभाव है। और ऊंचाई बदलने से कुछ मामलों में कुछ अन्य समस्याएं हो सकती हैं।
उन सभी के लिए जो टूलबार का उपयोग नहीं करना चाहते हैं bringToFront()और elevation="0dp"टूलबार को गायब कर देते हैं:
app:elevation="0dp"android:translationZ="0.1dp"मेरे साथ काम किया।
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
android:translationZ="0.1dp"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@null"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
नवीनतम appcompat संस्करणों के साथ, app:elevation="0.1dp"xml में चाल सेटिंग किसी भी अधिक काम नहीं करता है।
अब तक मैंने दो उपाय खोजे हैं।
सेटिंग के बजाय app:elevation, एक StateListAnimator का उपयोग करने का प्रयास करें। उदाहरण के लिए, कोड में:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0.1f));
appBarLayout.setStateListAnimator(stateListAnimator);
}एक आसान तरीका यह है कि आप अभी भी app:elevation="0dp"सामान्य रूप में xml में सेट हैं , लेकिन कोड में:
appBarLayout.bringToFront();इन दो चर्चाओं का श्रेय जाता है:
AppBarLayout के लिए ऊंचाई सेट करते समय टूलबार गायब हो जाता है
जब सेट एप्लिकेशन: उन्नयन = "0dp" तो हैम्बर्गर्मेनू टूलबार को नहीं दिखा रहा है
मैंने कोशिश की app:elevation="0dp", लेकिन टूलबार निराश करता है, लेकिन प्रयोग app:elevation="0.1dp"ने चाल बना दी।
आशा है कि यह किसी और की मदद करता है।
v25.0.0।
अपने AppBarLayout पर ऐप जोड़ें: उन्नयन = "0dp"। इस उदाहरण की तरह
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
प्रोग्रामेटिक रूप से आप इसका उपयोग कर सकते हैं: getSupportActionBar ()। SetElevation (0.0f);