最終更新:
moonlight_aska 2011年07月23日(土) 18:20:11履歴
タブ画面のタブにアイコンを設定するには, TabSpec.setIndicatorメソッドを使用する.


- res/drawable-xx/画像ファイル
- res/drawable-Xdpiディレクトリに, タブに貼り付ける画像を置く.
- Androidがサポートしている画像フォーマットは, 以下の4つである.
- Bitmap(.bmp)
- JPEG(.jpg)
- PNG(.png)
- GIF(.gif)
- TabSheet01.java
- タブ画面の作成は, タブ画面を作成するを参照.
- タブシートの設定で, TabSpec.setIndicatorメソッドにアイコンデータを渡す.
package com.moonlight_aska.android.tabsheet01;
import android.app.TabActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
public class TabSheet01 extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TabHostのインスタンスを取得
TabHost tabs = getTabHost();
LayoutInflater.from(this).inflate(R.layout.main, tabs.getTabContentView(), true);
// タブシートの設定
TabSpec tab01 = tabs.newTabSpec("TabSheet1");
tab01.setIndicator("TabSheet1");
tab01.setContent(R.id.sheet01_id);
tabs.addTab(tab01);
TabSpec tab02 = tabs.newTabSpec("TabSheet2");
tab02.setIndicator("TabSheet2", getResources().getDrawable(R.drawable.androidrobot));
tab02.setContent(R.id.sheet02_id);
tabs.addTab(tab02);
TabSpec tab03 = tabs.newTabSpec("TabSheet3");
tab03.setIndicator("TabSheet3");
tab03.setContent(R.id.sheet03_id);
tabs.addTab(tab03);
// 初期表示のタブ設定
tabs.setCurrentTab(0);
}
}
コメントをかく