我已经研究了很多我如何使用此代码对齐页面底部的标签,但我没有找到任何内容,我在代码中使用:
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("Home")
.setContent(new Intent(this, TabGroup1Activity.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("Search"/*, getResources().getDrawable(R.drawable.ic_launcher)*/)
.setContent(new Intent(this, TabGroup2Activity.class))
);
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("About Us")
.setContent(new Intent(this, TabGroup3Activity.class)));
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().setGravity(Gravity.BOTTOM);
TabGroup1Activity是:
public class TabGroup1Activity extends TabGroupActivity{
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startChildActivity("HomeActivity", new Intent(this,HomeActivity.class));
}
}
通过使用此代码,标签栏位于屏幕顶部,但我想将其放在底部..请提出建议,我发现这种方法很容易创建标签
答案 0 :(得分:0)
public void addNewTab(Context context, String title, int height){
TabHost tabHost = getTabHost(); // The activity TabHost
Intent intent = new Intent().setClass(context, HelloTabsActivity.class);
TabHost.TabSpec spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title).setContent(intent);
tabHost.addTab(spec);
int totalTabs = tabHost.getTabWidget().getChildCount();
((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).removeViewAt(0);
((TextView)((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).getChildAt(0)).setHeight(30);
tabHost.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = height;
}