我想在操作欄中使用標籤。爲了簡單起見,現在只有一個選項卡。問題是沒有view/ui可見。帶標籤的操作欄:不使用的分段
活性的onCreate functn包含凸片 -
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabs = new Vector<ActionBar.Tab>();
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab accountsTab = actionbar.newTab().setText("Accounts");
Fragment accountsFragment = new AccountsFragment();
accountsTab.setTabListener(new MyTabListener(accountsFragment));
actionbar.addTab(accountsTab);
tabs.add(accountsTab);
}
延伸片段(android.app.Fragment)片段AccountsFragment的oncreateview:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
textView.setText("SimpleFragmentText");
textView.setVisibility(View.VISIBLE);
textView.setTextSize(20);
return textView;
}
最後跳聽者如下:
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
if(fragment!=null) {
fragmentTransaction.add(fragment,"accounts");
fragmentTransaction.show(fragment);
}
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
if(fragment!=null) {
fragmentTransaction.remove(fragment);
}
}
所有其他功能都沒有被覆蓋。沒有任何顯示會顯示標題爲「帳戶」的標籤。
我的main.xml包含線性佈局。
您還沒有添加任何文本到文本視圖。 textView.setText(「Testing tabs」); –
即:textView.setText(「SimpleFragmentText」); – singhsumit
我錯過了XML? – singhsumit