各タブのカスタム レイアウトで TabWidget を使用して、フラグメントを含むタブを作成しました。1 つのことを除いて、すべてが機能しているように見えます。ICS 以上では、次のようになります。
しかし、Gingerbread では次のようになります。
はっきりとわかるように、ジンジャーブレッドには仕切りがありません。
そこで、質問が 2 つあります。まず、Gingerbread に仕切りを表示させる方法はありますか? 私はstackoverflowでさまざまな提案を試みましたが、表示されたくないだけです。
第二に、仕切りの外観をカスタマイズする方法はありますか? 私は使用してみました:
setDividerDrawable()
ICSで動作する画像を使用していますが、ジンジャーブレッドでヌルポインター例外が発生します。
(更新: 太字の問題に関しては、本当に厄介なことがわかりました。Gingerbread と ICS+ では仕切りの扱いが異なるようです。TabWidget.getChildAt() 呼び出しで Null ポインター例外が発生していました。仕切りが設定されている場合、 Gingerbread ディバイダは、それが含まれている Tabwidget の子ビューと見なされますが、ICS+ ではそうではありません (または無視されています)。したがって、getChildAt に使用しているインデックスは、Gingerbread ではタブウィジェットが 5 を見ているため、完全に間違っています。子 (3 つのタブと 2 つの仕切り) ですが、ICS では 3 つしか表示されません (3 つのタブのみ)。
また、仕切りの色を設定しようとしましたが、まったく機能しないようです。
タブの設定方法は次のとおりです。
/**
* Setup the tab host.
*/
private void initialiseTabHost(Bundle args) {
this.tabHost = (TabHost) findViewById(android.R.id.tabhost);
this.tabHost.setup();
TabInfo tabInfo = null;
addTab( this,
this.tabHost,
this.tabHost.newTabSpec(TAB_DASHBOARD).setIndicator(LayoutInflater.from(getApplicationContext())
.inflate(R.layout.tabview_dashboard, null)),
(tabInfo = new TabInfo(TAB_DASHBOARD, MonitoringTab.class.getName(), args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
//create alert list and alert details fragments, add alert list to the tab bar
tabInfo = new TabInfo(TAB_ALERT_DETAILS, AlertDetailTab.class.getName(), args);
this.mapTabInfo.put(tabInfo.tag, tabInfo);
tabInfo = new TabInfo(TAB_ALERTS, AlertListTab.class.getName(), args);
this.mapTabInfo.put(tabInfo.tag, tabInfo);
addTab( this,
this.tabHost,
this.tabHost.newTabSpec(TAB_ALERT_SHOWING).setIndicator(LayoutInflater.from(getApplicationContext())
.inflate(R.layout.tabview_alerts, null)),
tabInfo);
this.mapTabInfo.put(TAB_ALERT_SHOWING, tabInfo);
addTab( this,
this.tabHost,
this.tabHost.newTabSpec(TAB_ERRORQUEUE).setIndicator(LayoutInflater.from(getApplicationContext())
.inflate(R.layout.tabview_errorqueue, null)),
(tabInfo = new TabInfo(TAB_ERRORQUEUE, ErrorMessagesTab.class.getName(), args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
// Default to first tab
onTabChanged(TAB_DASHBOARD);
this.tabHost.setOnTabChangedListener(this);
}