Все, что я хочу сделать, это изменить цвет текста и вкладку, начертанной в моей вкладке. Я хотел бы решение, похожее на то, как я использую адаптеры для настройки блесны и ListViews ...Настройка табуляции Android TabHost в ActionBarActivity
Да, я уже видел это: ActionBarActivity with TabHost Решение есть, однако, использует FragmentTabHost и не очень решить проблему.
Вот мой TabHost:
<TabHost android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/tabHost" android:layout_weight="1">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="@+id/tab1" style="@style/details.tabContent">
...
</LinearLayout>
<LinearLayout android:id="@+id/tab2" style="@style/details.tabContent" >
...
</LinearLayout>
<LinearLayout android:id="@+id/tab3" style="@style/details.tabContent" >
...
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Вот мой ActionBarActivity код:
tabs=(TabHost)findViewById(R.id.tabHost);
/*tabs.getTabWidget().setDividerDrawable(R.drawable.tab_divider);*/
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Information");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Reviews");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag3");
spec.setContent(R.id.tab3);
spec.setIndicator("My Notes");
tabs.addTab(spec);
tabs.setCurrentTab(0);
ОБНОВЛЕНО КОД в настоящее время, createTabView только вызывается на первом runthrough из setupTab()
private void loadGUI() {
...
tabs=(TabHost)findViewById(R.id.tabHost);
tabs.setup();
/*
TODO: find a way to save the ids for each tab so I can later fill in values in each tab's listview and/or textview.
I have 2 tab content resources, 1 that just has a textview, the other a listview with a textview for setEmpty
int intTabContentDrugInfoID = setupTab("Info", R.layout.tab_content_standard);
int intTabContentReviewsID = setupTab("Reviews", R.layout.tab_content_list);
int intTabContentNotesID = setupTab("My Notes", R.layout.tab_content_list);*/
setupTab((TextView)findViewById(R.id.txtTabTitle), "Info");
setupTab((TextView)findViewById(R.id.txtTabTitle), "Reviews");
setupTab((TextView)findViewById(R.id.txtTabTitle), "My Notes");
tabs.setCurrentTab(0);
...
}
private void setupTab(final TextView view, final String tag) {
final View newTab = createTabView(tabs.getContext(), tag);
final Context tabsContext = tabs.getContext();
TabHost.TabSpec setContent = tabs.newTabSpec(tag).setIndicator(newTab).setContent(new TabContentFactory() {
public View createTabContent(String tag) {
// Here tabs_content is created in a similar way than the tab layout itself,
// with a layout file which is later inflated. All those ID's are from that file.
final View ll_view = LayoutInflater.from(tabsContext).inflate(R.layout.tab_content_standard, null);
final TextView view = (TextView) ll_view.findViewById(R.id.txtTabContent);
return ll_view;
}
});
tabs.addTab(setContent);
}
Это работает как шарм, Спасибо за ваше время! – Jarrette
Хорошо, есть недостаток в этом подходе. createTabContent только когда-либо вызывается на первой вкладке, а не на других ... очень странно. – Jarrette
Попробуйте выполнить отладку через 'Log.d()', это поведение, которое я никогда не испытывал, должен быть какой-то трюк в коде, вызывающий его неисправность. Я использую этот код в приложении, которое обрабатывает много этих событий, и оно работает хорошо. – nKn