Site icon IT Tutorial

Android Programlama -21

Merhaba arkadaşlar bu gün ki makalemde BottomNavigationView’ ın kullanımını göreceğiz.

Bir önceki makalede fragment konusuna değinmiştim. Okumadıysanız öncelikle onu okumanızı tavsiye ederim. Buradan okuyabilirsiniz.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.teka.icim_rahat.Icim_Rahat">

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />

</LinearLayout>

Yazdığımız xml kodlamasının çıktısının ekran görüntüsü yukarıdaki gibi dir. Ekran görüntüsündeki telefonun alt kısmında bulunan butonlar ButtomNavigationView sayesinde eklenmiştir uygulamaya. Ekranın en alt kısmın da bulunan butunlar’a tıklandığın da farklı sayfalar açılmaktadır. Bu sayfalarda fragment ile kodlanmış sayfalardır. BottomNavigationView’i dogru kullanabilmemiz için framelayout kullanmalıyız xml kodlamamız da.

Burada önemli bir noktada BottomNavigationView da kaç tane sayfa olacağını belirlediğimiz kısımdır. Bunu bir menu dosyası oluşturarak app:menu=”@menu/navigation” xml kodlaması yardımı ile belirlemiş oluruz.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="Fotograf" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_group_black_24dp"
        android:title="Ögretmen" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@drawable/ic_sentiment_satisfied_black_24dp"
        android:title="Ögrenci" />
    <item
        android:id="@+id/iletisim"
        android:icon="@drawable/ic_assignment_black_24dp"
        android:title="Hakkımızda">


    </item>
</menu>

Uygulamamız da kullandığımız menu kodları yukarıdaki gibidir. Her buton’u bir item temsil etmektedir. Her item’ın da id, icon ve tittle bilgileri mevcuttur.

Bir makalenin daha sonuna geldik, esenle kalın..

Exit mobile version