public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar=getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab().setText("All").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Not Called").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Called").setTabListener(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
if(tab.getPosition()==0){
FragmentTop fragmentTop = new FragmentTop();
getSupportFragmentManager().beginTransaction().replace(R.id.container,fragmentTop).commit();
}else if (tab.getPosition()==1){
FragmentTop2 fragmentTop2 = new FragmentTop2();
getSupportFragmentManager().beginTransaction().replace(R.id.container,fragmentTop2).commit();
}else if (tab.getPosition()==2){
FragmentTop3 fragmentTop3 = new FragmentTop3();
getSupportFragmentManager().beginTransaction().replace(R.id.container,fragmentTop3).commit();
}
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
0
A
回答
0
您現在應該使用已使其與AppCompat v7Toolbar。 (compile 'com.android.support:appcompat-v7:23.1.0'
)
1
試試這個:
toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle(R.string.app_name);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
}
tabHost=(FragmentTabHost)findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(),android.R.id.tabcontent);
bundle=new Bundle();
// to send data u can send it by binding it with bundle
tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Tab1"),
ShowStatusFragment.class,bundle);
tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("Tab2"),
ShowStatusFragment.class,bundle);
tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("Tab3"),
ShowStatusFragment.class,bundle);
0
你需要使用的android.support.v7.widget.Toolbar
AppCompat7
compile 'com.android.support:appcompat-v7:23.1.0'
添加在您的搖籃模塊應用
相關問題
- 1. 什麼是可能的解決方案
- 2. 爲什麼在PHP7.1中2級別的中斷已被刪除,其替代解決方案可能是什麼?
- 3. 解決方案從.net 4升級到4.6.1後性能下降
- 4. 'PageJacking'的解決方案是什麼?
- 5. 什麼樣的解決方案是thymeleaf?
- 6. 什麼是多級嵌套視圖的最佳解決方案?
- 7. 什麼是拖放最好的輕量級解決方案?
- 8. paymentWithProductIdentifier是什麼替代解決方案?
- 9. Haskell任務 - 什麼是解決方案
- 10. SVN升級 - 可能的解決方案,以加快它
- 11. GPU性能請求,什麼是最佳解決方案?
- 12. 抓取Whitepages的可能解決方案
- 13. 可能的DRM + epub/pdf解決方案?
- 14. 8女王的可能解決方案。
- 15. SQLNonTransientException的可能解決方案
- 16. 可能的模板解決方案
- 17. hasClass在IE9中不工作。什麼是替代或可能的解決方案?
- 18. 「checkSelfPermission」的解決方法或可能已棄用的版本是什麼?
- 19. Wordpress掛鉤被調用兩次。可能的解決方案?
- 20. 性能的解決方案
- 21. 解決二叉平方優化問題的最佳解決方案是什麼?
- 22. 爲什麼不在解決方案級別構建文件夾?
- 23. 爲什麼NuGet將軟件包放在「解決方案級別」?
- 24. Windows 7上的FileNet Visual WorkFlo - 性能下降解決方案?
- 25. 什麼是選擇真實解決方案的正確方法?
- 26. 構建nservicebus解決方案的最佳方式是什麼?
- 27. ,這是什麼工廠方法的最佳解決方案
- 28. 如果Swing已被棄用,那麼替代方案是什麼?
- 29. 爲什麼看不到解決方案
- 30. 解決方案有什麼不同
使用工具欄,而不是動作條 –
可我知道如何?代碼編輯是appriciated。謝謝 –
檢查出我有共享代碼的答案 –