我在应用程序中使用了支持操作栏并在 2 台设备 Nexus S 和 Nexus 7 中进行了测试,我发现关于标签栏宽度、Nexus S 标签栏填充宽度的不同结果,而 nexus 7 标签栏在左侧留下了一些空间。我使用了支持操作栏提供的默认主题,应用自定义主题不会影响操作栏,因为父样式必须是 Theme.AppCompat.Light
清单中的活动
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
班级:
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
ActionBar bar;
ViewPager pager;
TabsAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
bar = getSupportActionBar();
adapter = new TabsAdapter(getSupportFragmentManager());
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setHomeButtonEnabled(false);
pager.setAdapter(adapter);
pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When swiping between different app sections, select the
// corresponding tab.
// We can also use ActionBar.Tab#select() to do this if we have
// a reference to the
// Tab.
bar.setSelectedNavigationItem(position);
}
});
Tab hometab = bar.newTab();
hometab.setText("Home");
hometab.setTabListener(this);
bar.addTab(hometab);
Tab cameratab = bar.newTab();
cameratab.setText("Camera");
cameratab.setTabListener(this);
bar.addTab(cameratab);
Tab exploretab = bar.newTab();
exploretab.setText("Explore");
exploretab.setTabListener(this);
bar.addTab(exploretab);
bar.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
pager.setCurrentItem(arg0.getPosition());
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
}
这是屏幕截图