Showing posts with label Tab Menü. Show all posts
Showing posts with label Tab Menü. Show all posts

Wednesday, May 23, 2018

Tab Menü Oluşturma

Merhaba Arkadaşlar,

Bugün size Android Studio'da Tab Menü yapımını anlatacağım.

Öncelikle tab_activity.xml dosyamızı oluşturalım. Bununiçin TabHost ve TabWidget'dan faydalanacağız.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.hande.umut.yazbakalim.Tab_Activity">

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="72dp"
        tools:layout_editor_absoluteY="0dp"
        tools:ignore="MissingConstraints">

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

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</android.support.constraint.ConstraintLayout>

Daha sonra Tab_Activity.java dosyamızı oluşturuyoruz.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.hande.umut.yazbakalim;

import android.app.LocalActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * Created by Umut on 23.05.2018.
 */

public class Tab_Activity extends TabActivity {

    LocalActivityManager localActivityManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab_activity);

        localActivityManager = new LocalActivityManager(this, false);
        localActivityManager.dispatchCreate(savedInstanceState);

        TabHost tabh = (TabHost)findViewById(android.R.id.tabhost);
        tabh.setup(localActivityManager);
        TabHost.TabSpec tab1 = tabh.newTabSpec("Tab Menü 1");
        TabHost.TabSpec tab2 = tabh.newTabSpec("Tab Menü 2");
        TabHost.TabSpec tab3 = tabh.newTabSpec("Tab Menü 3");
        tab1.setIndicator("KOLAY");
        tab1.setContent(new Intent(this,Kolay_Activity.class));
        tab2.setIndicator("ORTA");
        tab2.setContent(new Intent(this,Orta_Activity.class));
        tab3.setIndicator("ZOR");
        tab3.setContent(new Intent(this,Zor_Activity.class));
        tabh.addTab(tab1);
        tabh.addTab(tab2);
        tabh.addTab(tab3);
    }

    @Override
    protected void onResume(){
        super.onResume();
        localActivityManager.dispatchResume();
    }

    @Override
    protected void onPause(){
        super.onPause();
        localActivityManager.dispatchPause(isFinishing());
    }
}

Android Manifest Dosyamızda Tab_Activity'yi başlangıç doyası olarak atadıktan sonra   </application>'un üzerine aşağıdaki kodları yazıyoruz.

1
2
3
  <activity android:name=".Kolay_Activity"></activity>
  <activity android:name=".Orta_Activity"></activity>
  <activity android:name=".Zor_Activity"></activity>