SORU
18 EKİM 2014, CUMARTESİ


Nasıl durum çubuğunun altında ActionBar/araç Çubuğunu tekrar görüntülemek için DrawerLayout kullanırım?

Durum çubuğunun arkasında eylem bar ve çekmece görüntüleyebilirsiniz yeni malzeme tasarımı Side Nav spec gördüm. Bunu nasıl uygulayabilirim?

CEVAP
18 EKİM 2014, CUMARTESİ


Çerçeve ve destek libs yeni işlevsellik tam olarak bunun için izin ver. Üç tane 'bulmacanın parçaları':

  1. Eylem gömebilirsiniz Toolbar kullanarak görünüm hiyerarşisi içinde bar.
  2. Bu 17* fitsSystemWindows *yani sistemi yapmak parmaklıkların arkasına koydu.
  3. Devre dışı bırakma Theme.Material'DrawerLayout orada yerine çizebilirsiniz normal durum çubuğu renklendirme.

Yeni appcompat kullanacağı tahmin ediyorum.

İlk olarak, düzeni bu gibi görünmelidir:

<!-- The important thing to note here is the added fitSystemWindows -->
<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">

    <!-- Your normal content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- We use a Toolbar so that our drawer can be displayed
             in front of the action bar -->
        <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="?attr/colorPrimary" />

        <!-- The rest of your content view -->

    </LinearLayout>

    <!-- Your drawer view. This can be any view, LinearLayout
         is just an example. As we have set fitSystemWindows=true
         this will be displayed under the status bar. -->
    <LinearLayout
        android:layout_width="304dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:fitsSystemWindows="true">

        <!-- Your drawer content -->

    </LinearLayout>

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

Faaliyet/Bölümü:

public void onCreate(Bundled savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Your normal setup. Blah blah ...

    // As we're using a Toolbar, we should retrieve it and set it
    // to be our ActionBar
    Toolbar toolbar = (...) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);

    // Now retrieve the DrawerLayout so that we can set the status bar color.
    // This only takes effect on Lollipop, or when using translucentStatusBar
    // on KitKat.
    DrawerLayout drawerLayout = (...) findViewById(R.id.my_drawer_layout);
    drawerLayout.setStatusBarBackgroundColor(yourChosenColor);
}

Sonra DrawerLayout durum çubuğunun arkasında görünür olduğundan emin olun gerekir. Değerleri-v21 tema değiştirerek yapmak:

values-v21/themes.xml

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

Not: Eğer <fragment android:name="fragments.NavigationDrawerFragment"> yerine kullanılır

<LinearLayout
    android:layout_width="304dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start"
    android:fitsSystemWindows="true">

    <!-- Your drawer content -->

</LinearLayout>

gerçek düzen, istenen etkiyi onCreateView yöntem döndüren bir görünüm fitsSystemWindows(boolean) ararsan sağlanacaktır.

@Override
public View onCreateView(LayoutInflater inflater, 
                         ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(
        R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setFitsSystemWindows(true);
    return mDrawerListView;
}

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bad Lip Reading

    Bad Lip Read

    22 Mart 2011
  • EmbarkToHeaven

    EmbarkToHeav

    3 EYLÜL 2007
  • Neil Cicierega

    Neil Ciciere

    22 Mart 2006