本文介绍了Android的动作栏选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在用行动吧标签的工作,他们与4.1装置显示完美,但是当我在较低的4.0版本,那么运行在相同的屏幕尺寸操作栏选项卡显示为动作条微调导航
我希望他们能够显示像这样的:
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpened(getIntent());
ParseUser的currentUser = ParseUser.getCurrentUser();
如果(的currentUser == NULL){
navigateToLogin();
} 其他 {
Log.i(TAG,currentUser.getUsername());
}
最后的动作条动作条= getActionBar();
//actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionPargerAdapter =新SectionPargerAdapter(这一点,getSupportFragmentManager());
mViewPager =(ViewPager)findViewById(R.id.pager);
mViewPager.setAdapter(mSectionPargerAdapter);
mViewPager.setOnPageChangeListener(新ViewPager.SimpleOnPageChangeListener(){
@覆盖
公共无效onPageSelected(INT位置){
actionBar.setSelectedNavigationItem(位置);
的for(int i = 0; I< mSectionPargerAdapter.getCount();我++){
//创建与对应于由所定义的页标题文本标签
//适配器。同时,指定此活动的对象,它实现
//该TabListener界面,回调(监听程序)进行时
//这个选项卡中选择。
actionBar.addTab(actionBar.newTab()
.setText(mSectionPargerAdapter.getPageTitle(I))
.setTabListener(MainActivity.this));}
}
});
}
@覆盖
公共无效onTabSelected(ActionBar.Tab选项卡,FragmentTransaction fragmentTransaction){
mViewPager.setCurrentItem(tab.getPosition());
}
@覆盖
公共无效onTabReselected(ActionBar.Tab选项卡,FragmentTransaction fragmentTransaction){
}
@覆盖
公共无效onTabUnselected(ActionBar.Tab选项卡,FragmentTransaction fragmentTransaction){
}
解决方案
这是通过优化系统来完成。第二种观点被称为堆叠操作栏和第一个被称为与微调的动作吧。你可以达到你想要的东西,首先将所有选项卡,然后设置的操作栏的模式
setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
Currently I'm working with action bar tabs they are shown perfectly with 4.1 device but when i run on same screen size in lower version 4.0 then the action bar tabs are shown as "ActionBar spinner navigation"
I want them to be shown like this one:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpened(getIntent());
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser == null) {
navigateToLogin();
} else {
Log.i(TAG, currentUser.getUsername());
}
final ActionBar actionBar = getActionBar();
//actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionPargerAdapter = new SectionPargerAdapter(this, getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionPargerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
for (int i = 0; i < mSectionPargerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab()
.setText( mSectionPargerAdapter.getPageTitle(i))
.setTabListener(MainActivity.this));}
}
});
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
解决方案
This is optimization done by system. The second view is called stacked action bar and first is called action bar with spinner. You can achieve what you want by first adding all tabs and then setting the mode of action bar as
setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
这篇关于Android的动作栏选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!