赞
踩
public class MainAbility extends FractionAbility {
private String[] str={"失物","拾物","发现","我的"};
private TabList tabList;
private StackLayout stackLayout;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(MainAbilitySlice.class.getName());
setUIContent(ResourceTable.Layout_ability_main);
initView();
}
private void initView(){
tabList = (TabList) findComponentById(ResourceTable.Id_tab_list_bottom);
stackLayout = (StackLayout) findComponentById(ResourceTable.Id_stack_layout);
for (int i = 0; i < str.length; i++) {
TabList.Tab tab = tabList.new Tab(getContext());
tab.setText(str[i]);
tabList.addTab(tab);
}
tabList.setFixedMode(true);
//默认第一个被选中
tabList.getTabAt(0).select();
switchPage(0);
/* tabList.setTabLength(100); // 设置Tab的宽度
tabList.setTabMargin(20); // 设置两个Tab之间的间距*/
tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
@Override
public void onSelected(TabList.Tab tab) {
// 当某个Tab从未选中状态变为选中状态时的回调
switchPage(tab.getPosition());
}
@Override
public void onUnselected(TabList.Tab tab) {
// 当某个Tab从选中状态变为未选中状态时的回调
}
@Override
public void onReselected(TabList.Tab tab) {
// 当某个Tab已处于选中状态,再次被点击时的状态回调
}
});
}
//模块页面切换
public void switchPage(int position){
switch (position){
case 0:
getFractionManager()
.startFractionScheduler()
.replace(ResourceTable.Id_stack_layout, new HomeFraction())
.submit();
break;
case 1:
getFractionManager()
.startFractionScheduler()
.replace(ResourceTable.Id_stack_layout, new FoundFraction())
.submit();
break;
case 2:
getFractionManager()
.startFractionScheduler()
.replace(ResourceTable.Id_stack_layout, new FindFraction())
.submit();
break;
case 3:
getFractionManager()
.startFractionScheduler()
.replace(ResourceTable.Id_stack_layout, new MeFraction())
.submit();
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical"
ohos:scrollbar_background_color="#b5c8c6">
<TabList
ohos:id="$+id:tab_list_bottom"
ohos:height="60vp"
ohos:width="match_parent"
ohos:layout_alignment="center"
ohos:orientation="horizontal"
ohos:text_alignment="center"
ohos:normal_text_color="#f4f0ef"
ohos:selected_text_color="#d2887b"
ohos:selected_tab_indicator_color="#f4f0ef"
ohos:selected_tab_indicator_height="0vp"
ohos:text_size="16vp"
ohos:fixed_mode="true"
ohos:align_parent_bottom="true"
ohos:background_element="#afb1b0"/>
<StackLayout
ohos:id="$+id:stack_layout"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:text_color="grey"
ohos:background_element="pink"
ohos:text_size="20vp"
ohos:layout_alignment="center"
ohos:text_alignment="center"
ohos:above="$id:tab_list_bottom"/>
</DependentLayout>
public class MeFraction extends Fraction {
@Override
protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
Component component=scatter.parse(ResourceTable.Layout_ability_me_fraction,container,false);
return component;
}
@Override
protected void onStart(Intent intent) {
super.onStart(intent);
Button btn_me_login=(Button)getFractionAbility().findComponentById(ResourceTable.Id_btn_me_login);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。