2015-07-06 4 views
5

नई एंड्रॉइड समर्थन डिज़ाइन लाइब्रेरी का उपयोग करते समय मेरे ऐप में एक पारदर्शी स्टेटस बार सेट करने का प्रयास करते समय मुझे कुछ समस्याएं आ रही हैं।नई समर्थन डिज़ाइन लाइब्रेरी का उपयोग करते समय स्टेटस बार पारदर्शी नहीं है

विशेष रूप से, मैं संयोजन CoordinatorLayout + AppBarLayout + CollapsingToolbarLayout + Toolbar इस श्रेणीबद्ध आदेश के साथ उपयोग कर रहा हूँ।

मैंने देखा कि स्टेटस बार पहले पारदर्शी आ गया है, तो मैं पारदर्शी से पूर्ण काला तक अनुवाद देख सकता हूं।

मैं मान/शैलियों में ऐसा करते हैं:

<item name="android:windowTranslucentStatus">true</item> 

और ये मेरे लेआउट में:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:elevation="4dp" 
    android:background="?android:colorPrimary" 
    android:layout_width="match_parent" 
    android:layout_height="128dp"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsingToolbarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     app:expandedTitleMarginStart="64dp"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:minHeight="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    </android.support.design.widget.CollapsingToolbarLayout> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="16dp" 
      android:layout_marginEnd="16dp" 
      app:cardCornerRadius="4dp" 
      app:cardElevation="6dp"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Latest Stories"/> 

       <TextView 
        android:id="@+id/latest_story_title" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Title Example"/> 

       <TextView 
        android:id="@+id/latest_story_preview" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Content Example, this should be around 250 chars"/> 

      </LinearLayout> 

     </android.support.v7.widget.CardView> 

    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab_add_story" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:fabSize="normal" 
    app:layout_anchor="@id/appbar" 
    app:layout_anchorGravity="bottom|right|end" 
    app:borderWidth="0dp" 
    android:layout_margin="16dp"/> 

<View 
    android:id="@+id/ripple_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="visible" 
    android:elevation="10dp" 
    android:stateListAnimator="@null" 
    android:clickable="false"/> 

(भयानक प्रारूपण के लिए क्षमा करें, ऐसा लगता है अतः संपादक नहीं होगा सहयोग करें)

क्या इसे भविष्य में रिलीज में ठीक किया जाएगा या इसे बाईपास करने का एक तरीका है ?

सभी को धन्यवाद।

+2

क्या आप getWindow() जोड़ रहे हैं। AddFlags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)? http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_TRANSLUCENT_STATUS – krystian71115

+0

धन्यवाद, यह काम करता है। मुझे कोड की इस पंक्ति से अवगत था, लेकिन मेरे कुछ अन्य ऐप्स में इसे किसी भी तरह की आवश्यकता नहीं थी। कृपया इसे एक उत्तर के रूप में लिखें ताकि मैं इसे स्वीकार कर सकूं! :) – Matteo

उत्तर

4

कोशिश करने के लिए - यह एपीआई स्तर 19 में जोड़ा गया:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_TRANSLUCENT_STATUS

संपादित करें: यह एपीआई स्तर में काम नहीं कर रहा से कम 19 (न्यूनतम किटकैट) की आवश्यकता

2

के मूल्यों/styles.xml इस लाइनों जोड़े

 <style name="MyTheme" parent="Base.MyTheme"></style> 


    <style name="Base.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">  
    <item name="colorPrimary">@color/primary_500</item> 

    <item name="colorPrimaryDark">@color/primary_700</item> 

    <item name="colorAccent">@color/accent_500</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="windowNoTitle">true</item> 
     <item name="android:windowBackground">@color/background_material_light</item> 

मान-V21 के लिए नीचे दिए गए कोड जोड़ें/styles.xml

<style name="MyTheme" parent="Base.MyTheme"> 
 <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
</style> 

नोट: आप केवल पारदर्शी स्थिति सेट कर सकते हैं लॉलीपॉप और उपरोक्त एपीआई पर इस विधि के साथ

MyThe को एप्लिकेशन स्तर थीम सेट करें मुझे पारदर्शी ध्वज सेट

+0

पारदर्शी स्टेटस बार एपीआई 1 से समर्थित है। यह किटकैट नो लॉलीपॉप है। – krystian71115

+0

इसे देखें: http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_TRANSLUCENT_STATUS – krystian71115

+0

लेकिन आप उपरोक्त कोड के माध्यम से किटकैट के लिए पारदर्शी स्टेटस बार सेट नहीं कर सकते हैं। मैंने लॉलीपॉप के लिए कोड स्निपेट दिया और लॉलीपॉप डिवाइस पोस्ट किया। KitKat उपकरणों पर पारदर्शी प्रभाव प्रदान करने के लिए systemtintedstatusbar जैसे कुछ बाहरी पुस्तकालय उपलब्ध हैं – Hvn

संबंधित मुद्दे