public class MainActivity extends FragmentActivity {@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); Actionbar actionbar = getActionbar(); actionbar.setNavigationMode(Actionbar.NAVIGATION_MODE_TABS); VIEw vIEw1 = LayoutInflater.from(this).inflate(R.layout.action_bar_layout,null); ((TextVIEw) vIEw1.findVIEwByID(R.ID.textVIEw)).setText("Tab1"); Actionbar.Tab tab1 = actionbar.newTab().setCustomVIEw(vIEw1); VIEw vIEw2 = LayoutInflater.from(this).inflate(R.layout.action_bar_layout,null); ((TextVIEw) vIEw2.findVIEwByID(R.ID.textVIEw)).setText("Tab2"); Actionbar.Tab tab2 = actionbar.newTab().setCustomVIEw(vIEw2); VIEw vIEw3 = LayoutInflater.from(this).inflate(R.layout.action_bar_layout,null); ((TextVIEw) vIEw3.findVIEwByID(R.ID.textVIEw)).setText("Tab3"); Actionbar.Tab tab3 = actionbar.newTab().setCustomVIEw(vIEw3); VIEw vIEw4 = LayoutInflater.from(this).inflate(R.layout.action_bar_layout,null); ((TextVIEw) vIEw4.findVIEwByID(R.ID.textVIEw)).setText("Tab4"); Actionbar.Tab tab4 = actionbar.newTab().setCustomVIEw(vIEw4); VIEw vIEw5 = LayoutInflater.from(this).inflate(R.layout.action_bar_layout,null); ((TextVIEw) vIEw5.findVIEwByID(R.ID.textVIEw)).setText("Tab5"); Actionbar.Tab tab5 = actionbar.newTab().setCustomVIEw(vIEw5); Fragment fragment1 = new Fragment1(); Fragment fragment2 = new Fragment2(); Fragment fragment3 = new Fragment3(); Fragment fragment4 = new Fragment4(); Fragment fragment5 = new Fragment5(); tab1.setTabListener(new MyTabsListener(fragment1,vIEw1)); tab2.setTabListener(new MyTabsListener(fragment2,vIEw2)); tab3.setTabListener(new MyTabsListener(fragment3,vIEw3)); tab4.setTabListener(new MyTabsListener(fragment4,vIEw4)); tab5.setTabListener(new MyTabsListener(fragment5,vIEw5)); actionbar.addTab(tab1); actionbar.addTab(tab2); actionbar.addTab(tab3); actionbar.addTab(tab4); actionbar.addTab(tab5); }class MyTabsListener implements TabListener { public Fragment fragment; public VIEw vIEw; public MyTabsListener(Fragment fragment,VIEw vIEw) { this.fragment = fragment; this.vIEw = vIEw; } @OverrIDe public voID onTabReselected(Tab tab,androID.app.FragmentTransaction ft) { System.out.println("onTabReselected"); } @OverrIDe public voID onTabSelected(Tab tab,androID.app.FragmentTransaction ft) { ((relativeLayout) vIEw.findVIEwByID(R.ID.rootElement)).setBackgroundcolor(color.WHITE); ((TextVIEw) vIEw.findVIEwByID(R.ID.textVIEw)).setTextcolor(color.BLACK); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.ID.mainFragement,fragment); fragmentTransaction.commit(); } @OverrIDe public voID onTabUnselected(Tab tab,androID.app.FragmentTransaction ft) { ((relativeLayout) vIEw.findVIEwByID(R.ID.rootElement)).setBackgroundcolor(color.BLACK); ((TextVIEw)vIEw.findVIEwByID(R.ID.textVIEw)).setTextcolor(color.WHITE); }} }
我的activity_main.xml是,
<?xml version="1.0" enCoding="utf-8"?><linearLayout androID:layout_gravity="center" androID:layout_height="fill_parent" androID:layout_wIDth="fill_parent" androID:orIEntation="vertical" xmlns:androID="http://schemas.androID.com/apk/res/androID"><linearLayout androID:ID="@+ID/fragment_container" androID:layout_height="match_parent" androID:layout_wIDth="match_parent" > <FrameLayout androID:ID="@+ID/mainFragement" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" ></FrameLayout></linearLayout>解决方法 *** 作栏不支持我认为的“垂直标签结构”.实际上,AndroID中通常不会出现“垂直标签结构”.您将看到的最接近的是横向平板电脑应用程序,左侧有一个ListVIEw控制右侧UI的内容(所谓的“主 – 细节”模式). 总结
以上是内存溢出为你收集整理的Android垂直 *** 作栏标签全部内容,希望文章能够帮你解决Android垂直 *** 作栏标签所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)