如何在同一个屏幕的底部和顶部设置标签。我需要在屏幕顶部显示一个标签,在同一个屏幕的底部显示另一个标签。任何人都知道如何做到这一点谢谢提前
答案 0 :(得分:0)
您好rakesh,您可以使用该链接在底部设置标签custom tabs 并查看此示例代码
public class Tab App extends Tab Activity {
@覆盖 protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
tabHost.removeAllViews();
TabWidget tabs = new TabWidget(this);
tabs.setId(android.R.id.tabs);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
tabs.setLayoutParams(params);
FrameLayout content = new FrameLayout(this);
content.setId(android.R.id.tabcontent);
content.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
RelativeLayout relative = new RelativeLayout(this);
relative.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
relative.addView(content);
relative.addView(tabs);
tabHost.addView(relative);
tabHost.setup();
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, AndroidBrowser.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tag1")
.setIndicator("tag1",res.getDrawable(R.drawable.cw))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, CWBrowser.class);
spec = tabHost.newTabSpec("tag2")
.setIndicator("tag2",res.getDrawable(R.drawable.cw))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CWBrowser.class);
spec = tabHost.newTabSpec("tag3")
.setIndicator("tag3",res.getDrawable(R.drawable.cw))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}`