SORU
4 Kasım 2014, Salı


Navigasyon Çekmece yarı saydam Durum Çubuğu üzerinde çalışmıyor

Android proje üzerinde çalışıyorum ve Navigasyon Çekmece başlatıyorum. Yeni Material Design Spec Material Design Checklist okuyorum.
Spec bölmesinden dışarı kaydırın durum çubuğu da dahil olmak üzere her şeyin üstünde yüzer ve yarı-şeffaf Durum Çubuğu üzerinde gerektiğini söylüyor.

Navigasyon benim paneli durum çubuğu ama herhangi bir şeffaflık var onun üzerinde. Bu kodu takip ediyorumBu YÜZDENGoogle geliştiriciler önerilen post spot, How do I use DrawerLayout to display over the ActionBar/Toolbar and under the status bar? yukarıdaki link blog.

Aşağıda XML düzeni

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@ id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            android:id="@ id/my_awesome_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:background="@color/appPrimaryColour" />
    </LinearLayout>
    <LinearLayout android:id="@ id/linearLayout"
        android:layout_width="304dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:fitsSystemWindows="true"
        android:background="#ffffff">
        <ListView android:id="@ id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:choiceMode="singleChoice"></ListView>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

Aşağıda uygulamalar benim tema

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/appPrimaryColour</item>
        <item name="colorPrimaryDark">@color/appPrimaryColourDark</item>
        <item name="colorAccent">@color/appPrimaryColour</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>

    </style>

Aşağıda uygulamalarım v21 tema

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/appPrimaryColour</item>
    <item name="colorPrimaryDark">@color/appPrimaryColourDark</item>
    <item name="colorAccent">@color/appPrimaryColour</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Aşağıda onCreate yöntemi

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout)findViewById(R.id.my_drawer_layout);
    mDrawerList = (ListView)findViewById(R.id.left_drawer);

    mDrawerLayout.setStatusBarBackgroundColor(
        getResources().getColor(R.color.appPrimaryColourDark));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        LinearLayout linearLayout = 
            (LinearLayout)findViewById(R.id.linearLayout);
        linearLayout.setElevation(30);
    }

Aşağıda birekran görüntüsünavigasyon çekmeceyi üst yarı şeffaf olmadığını göstermek için

Screenshot showing non transparent over the status bar

CEVAP
14 Kasım 2014, Cuma


Durum çubuğu arka planı beyaz, çekmece LinearLayout arka plan. Neden? Ayarları fitsSystemWindows="" DrawerLayout ve içindeki LinearLayout için. gerçek Bu LinearLayout durum çubuğunu şeffaf olan) arkasında genişletmek için neden olur. Böylece, çekmece için arka plan, durum çubuğunda beyaz parçası yapmak.

enter image description here
Eğer çekmece durum çubuğunun arkasında uzatmak için (tüm durum çubuğu yarı şeffaf bir arka plan olmasını) istiyor musun diye, iki şey yapabilirsiniz:

1) sadece LinearLayout ve içindeki içerik arka plan rengi herhangi bir arka plan değeri kaldırabilirsiniz. Ya

2) LinearLayout fitsSystemWindows="true" kaldırabilirsiniz. Bu daha mantıklı ve daha temiz bir yaklaşım olduğunu düşünüyorum. Ayrıca navigasyon çekmece uzatmak istemeyeceği bir gölge altında durum çubuğunu dökme olmaktan kaçının.

enter image description here
Eğer istediğiniz çekmeceni uzatmak arkasındaki durum çubuğu ve bir yarı-şeffaf durum çubuğu boyutlu kaplama, kullanabilirsiniz ScrimInsetFrameLayout gibi bir konteyner için çekmeceni içerik (Liste Görünümü) ve set durum çubuğu arkaplanı kullanarak app:insetForeground="#4000". Tabii ki, istediğiniz herhangi bir şey için #4000 değiştirebilirsiniz. fitsSystemWindows="true" burada! takip etmeyi unutmayın

Ya da eğer içeriği kaplaması ve sadece düz renk görüntülemesini istiyorsanız Eğer, istediğiniz herhangi bir şey için LinearLayout arka plan ayarlayabilirsiniz. İçerik ve arka plan ayrı ayrı olsa! ayarlamak için unutma

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Damian Winter

    Damian Winte

    27 ŞUBAT 2007
  • HTC Tutorials

    HTC Tutorial

    21 EYLÜL 2010
  • TantalizingTrance

    TantalizingT

    15 ŞUBAT 2009