我知道应用程序崩溃是因为我的自定义 titleBar 和 ActionBar 之间的冲突。但我无法理解的是为什么即使我没有实现 CustomView 也无法使用 ActionBar.newTab().setText(categoryList[0])
这是我的自定义标题栏样式:
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
/***
我的活动中的代码:
public class TestingEndlessAdapterFragmentDemo extends Activity implements
ActionBar.TabListener {
private TestingEndlessAdapterFragment simple = null;
private TestingEndlessAdapterCustomTaskFragment customTask = null;
private static enum Tabs {
TAB_FUN, TAB_MOVIE, TAB_STANDUP, TAB_MUSIC;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
final ActionBar bar = getActionBar();
// titlebar_title.setText("Prefeerences");
// titlebar_icon.setImageResource(R.drawable.titlebar_list);
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
String[] categoryList = new String[4];
categoryList = getResources().getStringArray(R.array.category_name);
bar.addTab(bar.newTab().setText(categoryList[0]).setTabListener(this)
.setTag(Tabs.TAB_FUN));
bar.addTab(bar.newTab().setText(categoryList[1]).setTabListener(this)
.setTag(Tabs.TAB_MOVIE));
bar.addTab(bar.newTab().setText(categoryList[2]).setTabListener(this)
.setTag(Tabs.TAB_STANDUP));
bar.addTab(bar.newTab().setText(categoryList[3]).setTabListener(this)
.setTag(Tabs.TAB_MUSIC));
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
onTabSelected(tab, ft);
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
switch ((Tabs) tab.getTag()) {
case TAB_FUN:
showSimple(ft);
break;
case TAB_MOVIE:
showCustom(ft);
break;
case TAB_STANDUP:
showCustom(ft);
break;
case TAB_MUSIC:
showCustom(ft);
break;
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// no-op
}
private void showSimple(FragmentTransaction ft) {
if (simple == null) {
simple = new TestingEndlessAdapterFragment();
}
ft.replace(android.R.id.content, simple);
}
private void showCustom(FragmentTransaction ft) {
if (customTask == null) {
customTask = new TestingEndlessAdapterCustomTaskFragment();
}
ft.replace(android.R.id.content, customTask);
}
}
一切正常,除了 setText()