2015-05-17 16 views
6

Android'de Gezinme Çekmecesinin uygulamalarını öğrenmeye çalışıyorum.Bildirim Çubuğu, Nav Drawer'ı uyguladıktan sonra gri renktedir

bir etkinlik olarak, ben Navigasyon Çekmece Durum Çubuğunda (saydam) altında ve App Bar gelip her şey gayet iyi çalışıyor yaptık. (Sol ekran görüntüsü)

aynı App başka etkinlikte, öyleyim Uygulama Çubuğunun altına çeken Gezinme Çekmecesi oluşturmaya çalışıyor. Ancak burada, durum çubuğu bir nedenden ötürü gri renge döner (nav çekmecesi açık veya kapalı) (Sağ Ekran). Bunun dışında her şey iyi görünüyor.

enter image description here

yeşil Nav Çekmece

bir parçasıdır: Aşağıda

görüntü var.

Bilmek istediğim durumun nasıl normal hale getirileceğidir (koyu gölgeli. Lütfen, App Bar'daki ikiz ok simgesini tıklarsam, beni başka bir Nav çekmecesini içeren başka bir etkinliğe götüreceğini unutmayın. . (şeffaf Durum Çubuğunda altına giriyor ekranın Tam yükseklik ve) Malzeme Tasarımda gibi bu ekran görüntüsünün sol tarafında gösterilir Aşağıda

kodudur.

MainActivity.java:

public class MainActivity extends ActionBarActivity { 
    Toolbar toolbar; 
    DrawerLayout xDrawerLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_alt); 

     toolbar = (Toolbar) findViewById(R.id.app_bar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 

     xDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     xDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primary_dark)); 

     NavDrawerFragment mfragment = (NavDrawerFragment) getFragmentManager().findFragmentById(R.id.nav_drawer_fragment); 
     mfragment.SetUp(xDrawerLayout, toolbar, R.id.nav_drawer_fragment); 
    } 
... 

activity_alt.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <include 
     android:id="@+id/app_bar" 
     layout="@layout/app_bar" /> 


    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello_world" /> 

     </RelativeLayout> 

     <fragment 
      android:id="@+id/nav_drawer_fragment" 
      android:name="com.rt.droid.mattest.NavDrawerFragment" 
      android:layout_width="@dimen/nav_drawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      tools:layout="@layout/fragment_nav_drawer" /> 


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

</LinearLayout> 

NavDrawerFragment.java:

public class NavDrawerFragment extends Fragment { 

    private ActionBarDrawerToggle mDrawerToggle; 
    private DrawerLayout mDrawerLayout; 
    public DrawerLearner yDrawerLearner; 

    public NavDrawerFragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View fView = inflater.inflate(R.layout.fragment_nav_drawer, container, false); 
     //fView.setFitsSystemWindows(true); 
     fView.setBackgroundColor(getResources().getColor(R.color.accent)); 
     return fView; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    public void SetUp(DrawerLayout drawerLayout, Toolbar toolbar, int frag_id) { 
     this.mDrawerLayout = drawerLayout; 
     View drawerFrag = getActivity().findViewById(frag_id); 
     mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { 
      @Override 
      public void onDrawerOpened(View drawerView) { 
       super.onDrawerOpened(drawerView); 
       getActivity().invalidateOptionsMenu(); 
      } 

      @Override 
      public void onDrawerClosed(View drawerView) { 
       super.onDrawerClosed(drawerView); 
       getActivity().invalidateOptionsMenu(); 
      } 
     }; 

     yDrawerLearner = new DrawerLearner(mDrawerLayout, drawerFrag, getActivity()); 
     yDrawerLearner.execute(); 

     this.mDrawerLayout.setDrawerListener(mDrawerToggle); 
     mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primary_dark)); 

     mDrawerLayout.post(new Runnable() { 
      @Override 
      public void run() { 
       mDrawerToggle.syncState(); 
      } 
     }); 

    } 
} 

fragment_nav_drawer.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.rt.droid.mattest.NavDrawerFragment"> 

    <!-- TODO: Update blank fragment layout --> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/hello_blank_fragment" /> 

</FrameLayout> 

app_bar.xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/primary" 
    app:popupTheme="@style/AppTheme.PopupMenu" 
    android:theme="@style/AppTheme.Toolbar"> 

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

styles.xml:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="AppTheme.Base"> 
     <!-- Customize your theme here. --> 
    </style> 

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/primary</item> 
     <item name="colorPrimaryDark">@color/primary_dark</item> 
     <item name="colorAccent">@color/accent</item> 
    </style> 

    <style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark"> 
     <item name="android:textColorPrimary">@color/primary_text</item> 
     <item name="android:textColorSecondary">@color/accent</item> 
    </style> 

    <style name="AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark"> 
     <item name="android:background">@color/accent</item> 
    </style> 

</resources> 

styles.xml (V21):

<resources> 
    <style name="AppTheme" parent="AppTheme.Base"> 
     <!-- Customize your theme here. --> 
     <item name="android:colorPrimary">@color/primary</item> 
     <item name="android:colorPrimaryDark">@color/primary_dark</item> 
     <item name="android:colorAccent">@color/accent</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
     <item name="android:windowTranslucentStatus">true</item> 
    </style> 

</resources> 

colors.xml (ekran gösteren renk örnekleri):

colors.xml

Not: Diğer gezinme çekmecelerimin çalışmaz hale gelmesini sağlayan stillerden ödün vermek istemiyorum. Diğer bir deyişle, her iki tür gezinme çubuğunun aynı uygulamada beklendiği gibi çalıştığı bir çözümü tercih ederim.

Lütfen herhangi bir bilgiye ihtiyacınız olursa lütfen bildirin ve gerekirse düzenleyin. Düzenleme: Netlik için app_bar.xml & colors.xml eklendi.

+0

bu kaldırmak : DrawerLayout.setStatusBarBackgroundColor (getResources(). GetColor (R.color.primary_dark)); –

+0

kaldırıldı, ancak durum çubuğu hala gri. – rapidclock

+0

sonra sorun araç çubuğunda –

cevap

12

Ama burada, durum çubuğu O beyaz arka plan üzerinde saydam (% 25 siyah) Durum çubuğu arka planı nedense

için gri olana altındaki etkinlik. i bilmek istedikleriniz

İkinci etkinlik için saydam durum çubuğunu devre dışı bırakmanız gerekir

normal duruma nasıl olduğunu. Sizin tema tanımında bu hat ile aktive edilir:

<item name="android:windowTranslucentStatus">true</item> 
<item name="android:statusBarColor">@color/primary_dark</item> 

Yani ya bir alt tema tanımlayabilir ve false işaretleyin geçersiz veya etkinlikten bu arayarak bayrağı programlı temizleyin:

if (Build.VERSION.SDK_INT >= 21) { 
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
    getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark); 
} 
+0

, ne dediğinizi deneyimledim .. TranslucentStatus hakkında haklısınız ve söylediğim gibi programlı olarak ayarlıyorum. Şimdi durum çubuğu beyaz (şimdi sadece şeffaftır). Şeffaflığı nasıl kapatabilirim ve birincil_dark rengine (programlı olarak) ayarlıyorum? – rapidclock

+0

@rapidclock Benim hatam, şimdi kontrol et. –

0

eklenti style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 
+0

hmm, bunun olduğunu düşünmüyorum .. ilk satır yine de yorumlanır. İkinci satır, sadece yeşil renge fragman (yani Çekmece) verir. – rapidclock

+0

Üzgünüz .. Şimdi kontrol et .. –

+0

Denedim .. bir şeyi ne yazık ki değiştirmedim. Aslında bu satır, durumu durum çubuğuna koyu renk vererek sorunu çözmeye çalışıyordu, ama bir şekilde bir fark yaratmıyordu. Cevabınızdan sonra – rapidclock

İlgili konular