タブ付きアプリケーションを構築しています。TabHost との相性は抜群です。残念ながら、私のチーム リーダーはタブの外観が好きではありません。彼は、小さなアイコンとタブ間の隙間が好きではありません。したがって、TabHost を変更するか、ActivityGroup を使用する必要があります。
私の最初の試みは、TabHost を変更することでした。
これが私のタブの1つのドローアブルです:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_timeline_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_timeline_white" />
<!-- This is a state-list drawable, which you will apply as the tab image. When the tab state changes, the tab icon will automatically switch between the images defined here. -->
</selector>
メイン アクティビティでタブを初期化します。
// Initialize a TabSpec for each tab and add it to the TabHost
intent = new Intent().setClass(this, TimelineActivity.class);
spec = tabHost.newTabSpec("timeline") .setIndicator("",
res.getDrawable(R.drawable.ic_tab_timeline))
.setContent(intent);
tabHost.addTab(spec);
(Indicator を空白に設定していることに注意してください。)
次に、背景画像を設定します。
TabWidget tw = getTabWidget();
//changeTabWidgetStyle(tw);
View tempView = tabHost.getTabWidget().getChildAt(0);
tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.timeline_on));
これにより、背景が目的の画像に正常に設定されます。ただし、私のタブにはまだ小さなアイコンがあり、背景画像に重なっています。どうすればアイコンを消すことができますか? タブを初期化するときに Drawable を null に設定しようとしましたが、これによりアプリがクラッシュします。
これを機能させることができたとしても、タブ間にまだスペースが残っているようです。どうすればそれらを取り除くことができますか?
これがうまくいかない場合は、ActivityGroup を使用する必要があるかもしれません。しかし、それはもっと複雑に思えるので、私はむしろそうしません。
私はこの例を使用しています: Android: ActivityGroup を使用してアクティビティを埋め込む
LocalActivityManager mgr = getLocalActivityManager();
Intent i = new Intent(this, SomeActivity.class);
Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;
if(wd != null) {
mSomeContainer.addView(wd);
}
「タブ」を取得してレイアウトを変更および拡張できますが、ローカル アクティビティを追加できません。ビューを追加する「コンテナ」の種類がわかりません。私のxmlレイアウトはどのように見えるべきですか?