본문 바로가기

[Android] 지하철 어플 만들기 1탄(탭레이아웃)

반응형

Xml파일        

   

<?xml version="1.0" encoding="utf-8"?>

   

<TabHost

  android:id="@android:id/tabhost"

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

  xmlns:android="http://schemas.android.com/apk/res/android"

>

    

<LinearLayout

  android:id="@+id/LinearLayout01"

  android:layout_height="fill_parent"

  android:layout_width="fill_parent"

>

      

<TabWidget

  android:id="@android:id/tabs"

  android:layout_height="wrap_content"

  android:layout_width="fill_parent" />

      

      

<FrameLayout

  android:id="@android:id/tabcontent"

  android:layout_height="fill_parent"

  android:layout_width="fill_parent"

    >

    </FrameLayout>

  </LinearLayout>

</TabHost>

   

   

Tablayout.java 파일

   

package com.android.tab;

   

import android.app.TabActivity;

import android.content.Intent;

import android.content.res.Resources;

import android.os.Bundle;

import android.widget.TabHost;

   

public class TabLayoutTest extends TabActivity {

  /** Called when the activity is first created. */

  @Override

  public void onCreate(Bundle savedInstanceState) 

  {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

   

    Resources res = getResources(); //리소스 가져오기

   

    TabHost tabhost = getTabHost();  //탭호스트

    TabHost.TabSpec spec;  //탭의 속성변경

   

    spec = tabhost.newTabSpec("Tab1");  //초기화!!!!

   

    Intent intent = new Intent()

    .setClass(this, SubActivity1.class);

   

    spec.setIndicator("Tab1",

        res.getDrawable(android.R.drawable.ic_menu_agenda))

        .setContent(intent);

    //초기화된 스펙을 탭에 붙이기!!!!

    tabhost.addTab(spec);

   

    ///두번째 !!!!!

    intent = new Intent().setClass(this, SubActivity2.class);

    spec = tabhost.newTabSpec("Tab2")

    .setIndicator("Tab2"

        res.getDrawable(android.R.drawable.ic_menu_edit))

        .setContent(intent);

    tabhost.addTab(spec);

    //세번째 !!!!!

    intent = new Intent().setClass(this, SubActivity3.class);

    spec = tabhost.newTabSpec("Tab3")

    .setIndicator("Tab3",

        res.getDrawable(android.R.drawable.ic_menu_help))

        .setContent(intent);

    tabhost.addTab(spec);

  }

}

   

   

   

   

   

SubActivity1

   

package com.android.tab;

   

import android.app.Activity;

import android.os.Bundle;

   

public class SubActivity1 extends Activity {

   

  @Override

  protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);

    //작성!!!!!!

  }

   

}

   

   

반응형
-->