通用app界面框架AppGeneralFrameWork[app通用框架][API V6]


目录
  • 1. 名称
  • 2. app实现关键技巧
  • 3. java源代码
    •   3.1 FloatsOfColorMatrix.java
    •   3.2 CommonListContainerItem.java
    •   3.3 CommonListContainerProvider.java
    •   3.4 FirstCenterPgSdProvider.java
    •   3.5 MainAbilitySlice.java
    •   3.6 MainAbility.java
    •   3.7 MyApplication.java
  • 4. XML源代码
    •   4.1 UI背景XML
      •    4.1.1 background_ability_main.xml
      •    4.1.2 background_common_directional.xml.xml
      •    4.1.3 background_common_listcontainer_item.xml
      •    4.1.4 background_common_subdirectional.xml
      •    4.1.5 background_searchbar_rootdl.xml
      •    4.1.6 background_titlebar_rootdl.xml
    •   4.2 主页与子布局XML
      •    4.2.1 ability_main.xml
      •    4.2.2 common_listcontainer_item.xml
      •    4.2.3 dtpage_center.xml
      •    4.2.4 firstpage_center.xml
      •    4.2.5 mepage_center.xml
      •    4.2.6 messagepage_center.xml
      •    4.2.7 pageslider_directionallayout.xml
      •    4.2.8 searchbar.xml
      •    4.2.9 titlebar.xml
      •    4.2.10 writepage_center.xml
  • 5. 图像资源
    •   5.1 点赞图标
    •   5.2 评论图标
    •   5.3 收藏图标
    •   5.4 搜索图标(来自鸿蒙官网系统图标下载)
  • 6. app截图
  • 7. app运行视频(本地模拟器运行)

1. 名称

  • 本专栏文章内容再次说明:全专栏处于鸿蒙应用开发领域,每篇文章都是一个完整的项目
  • 本专栏不讲HarmonyOS应用开发基础教程,有关教程在CSDN上有很多优质的文章可供参阅
  • 本次项目是一个比较通用app的整体界面框架的实现,命名为:app通用框架、AppGeneralFrameWork。
  • 如果新手读者朋友已经阅读过前面几篇文章的话,这篇文章则是一个更加框架化的东西,供大家参阅。
  • 项目已经上传至Gitee仓库中:AppGeneralFrameWork
  • app图标:
    请添加图片描述

2. app实现关键技巧

整体框架解读:

  • 页面整体划分:上、中、下三部分,除下部底部导航栏外,上、中都需要使用动态装载XML的技术,根据切换不同的底部tab标签,装载相应的组件。
  • 底部导航栏:采用TabList组件。
  • 首页:上部一个搜索栏、中部一个TabList和PageSlider的双向绑定组件,其中PagesSlider的每页都已经预装有一个DirectionalLayout,可以根据每页不同的需要装载不同的组件显示内容。(在上一篇文章中已经介绍过,如何给PageSlider装载不同的组件内容)
  • 榜单:采用一个ListContainer组件,显示榜单数据。设定了一个通用ListContanier初始化函数,这里采用的是通用版本。
  • 创作:采用TextField组件,并且设置一个“取消”和一个“发布”按钮。
  • 消息:采用三个Image组件分别表示“点赞”、“评论”、“收藏”,在其下方有一个通用版本的ListContainer,根据点击的三个按钮,加载相应的数据源,然后使用notifyDataChanged()即可刷新显示的内容。
  • 我的:一个Image组件显示用户头像、一个并列的Text显示用户名称,在其下方采用16宫格的形式,每个宫格都已经预装有DirectionalLayout,可以根据需要在宫格中放置不同的组件内容。

3. java源代码

  3.1 FloatsOfColorMatrix.java

package com.tdtxdcxm.appgeneralframework.colormatrixfloats;

public class FloatsOfColorMatrix {
    public static final float[] floats1 = {
            0,0,0,0,255,
            0,0,0,0,250,
            0,0,0,0,240,
            0,0,0,0,100
    };
    public static final float[] floats2 = {
            0,0,0,0,255,
            0,0,0,0,218,
            0,0,0,0,185,
            0,0,0,0,100
    };
    public static final float[] floats3 = {
            0,0,0,0,255,
            0,0,0,0,250,
            0,0,0,0,205,
            0,0,0,0,100
    };
    public static final float[] floats4 = {
            0,0,0,0,240,
            0,0,0,0,255,
            0,0,0,0,240,
            0,0,0,0,100
    };
    public static final float[] floats5 = {
            0,0,0,0,230,
            0,0,0,0,230,
            0,0,0,0,250,
            0,0,0,0,100
    };
    public static final float[] floats6 = {
            0,0,0,0,255,
            0,0,0,0,165,
            0,0,0,0,79,
            0,0,0,0,100
    };
    public static final float[] floats7 = {
            0,0,0,0,64,
            0,0,0,0,224,
            0,0,0,0,208,
            0,0,0,0,100
    };

    public static final float[][] floats = {floats1,floats2,floats3,floats4,floats5,floats6,floats7};
}

  3.2 CommonListContainerItem.java

package com.tdtxdcxm.appgeneralframework.item;


public class CommonListContainerItem{
    private String information = "";

    public CommonListContainerItem(String information) {
        this.information = information;
    }

    public void setInformation(String information) {
        this.information = information;
    }

    public String getInformation() {
        return information;
    }

    @Override
    public String toString() {
        return "CommonListContainerItem{" + "information='" + information + '\'' + '}';
    }
}

  3.3 CommonListContainerProvider.java

package com.tdtxdcxm.appgeneralframework.provider;

import com.tdtxdcxm.appgeneralframework.ResourceTable;
import com.tdtxdcxm.appgeneralframework.item.CommonListContainerItem;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;

import java.util.ArrayList;


public class CommonListContainerProvider extends BaseItemProvider{
    public static CommonListContainerProvider commonListContainerProvider = null;//用于记录已经new的对象引用,便于调用notifyDataChanged();

    private ArrayList commonlistcontaineritem_list;
    private AbilitySlice abilitySlice;

    public CommonListContainerProvider(ArrayList commonlistcontaineritem_list,AbilitySlice abilitySlice,String providername) {
        this.commonlistcontaineritem_list = commonlistcontaineritem_list;
        this.abilitySlice = abilitySlice;
        CommonListContainerProvider.commonListContainerProvider = this;
    }

    @Override
    public int getCount() {
        return commonlistcontaineritem_list != null ? commonlistcontaineritem_list.size():0;
    }

    @Override
    public Object getItem(int i) {
        if(commonlistcontaineritem_list == null || (i < 0 || i >= commonlistcontaineritem_list.size())){
            return null;
        }
        return commonlistcontaineritem_list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        final Component cmpt;
        if(component == null){
            cmpt = LayoutScatter.getInstance(abilitySlice).parse(ResourceTable.Layout_common_listcontainer_item,null,false);
        }
        else{
            cmpt = component;
        }

        CommonListContainerItem commonListContainerItem = commonlistcontaineritem_list.get(i);
        Text common_listcontainer_item_text = (Text) cmpt.findComponentById(ResourceTable.Id_common_listcontainer_item_text);
        common_listcontainer_item_text.setText(commonListContainerItem.getInformation());

        return cmpt;
    }
}

  3.4 FirstCenterPgSdProvider.java

package com.tdtxdcxm.appgeneralframework.provider;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.PageSliderProvider;

import java.util.ArrayList;

public class FirstCenterPgSdProvider extends PageSliderProvider {
    public static FirstCenterPgSdProvider firstCenterPgSdProvider = null;
    private ArrayList firstcenter_pagesliderslist = new ArrayList<>();

    public FirstCenterPgSdProvider(ArrayList firstcenter_pagesliderslist) {
        this.firstcenter_pagesliderslist = firstcenter_pagesliderslist;
        FirstCenterPgSdProvider.firstCenterPgSdProvider = this;
    }

    @Override
    public int getCount() {
        return firstcenter_pagesliderslist.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        DirectionalLayout directionalLayout = firstcenter_pagesliderslist.get(i);
        componentContainer.addComponent(directionalLayout);

        return directionalLayout;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}

  3.5 MainAbilitySlice.java

package com.tdtxdcxm.appgeneralframework.slice;

import com.tdtxdcxm.appgeneralframework.ResourceTable;
import com.tdtxdcxm.appgeneralframework.colormatrixfloats.FloatsOfColorMatrix;
import com.tdtxdcxm.appgeneralframework.item.CommonListContainerItem;
import com.tdtxdcxm.appgeneralframework.provider.CommonListContainerProvider;
import com.tdtxdcxm.appgeneralframework.provider.FirstCenterPgSdProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.render.ColorMatrix;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;

import java.util.ArrayList;



public class MainAbilitySlice extends AbilitySlice {
    private String[] bottomnames = {"首页","榜单","创作","消息","我的"};
    private String[] firstcenter_names = {"HarmonyOS","c语言","java","javascript","数据结构与算法","linux","python"};

    private DirectionalLayout approotdl_topdl,approotdl_centerdl,approotdl_bottomdl;

    private TabList firstpage_center_rootdl_tablist;
    private TabList approotdl_bottomdl_tablist;

    private PageSlider firstpage_center_rootdl_PageSlider;

    private ListContainer dtpage_center_rootdl_listcontainer,messagepage_center_rootdl_listcontainer;

    private final ArrayList bottomtabslist = new ArrayList<>();
    private final ArrayList firstcenter_tabslist = new ArrayList<>();

    private final ArrayList firstcenter_pagesliderslist = new ArrayList<>();

    private final ArrayList commonlistcontaineritem_list = new ArrayList<>();//普通listcontainer数据源列表

    public void toastShow(String info){
        ToastDialog toastDialog = new ToastDialog(this.getContext());
        toastDialog.setText(info);
        toastDialog.setTransparent(true);
        toastDialog.setDuration(100);
        toastDialog.setAlignment(LayoutAlignment.CENTER);
        toastDialog.show();
    }

    public void initCommonListContainer(ListContainer commonlistContainer){
        commonlistContainer.setItemProvider(new CommonListContainerProvider(commonlistcontaineritem_list,this, "dt_listcontainer"));
        commonlistContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                toastShow("已经点击了第"+i+"个!准备跳转详情页!");
            }
        });
    }


    public void installSearchBar(){
        if(approotdl_topdl == null){
            return;
        }
        if(approotdl_topdl.getChildCount() != 0){
            approotdl_topdl.removeAllComponents();
        }
        DirectionalLayout searchbar_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_searchbar,null,true);
        TextField searchtextField = (TextField) searchbar_rootdl.getComponentAt(0);
        Image searchimage = (Image) searchbar_rootdl.getComponentAt(1);

        searchtextField.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int i, int i1, int i2) {

            }
        });

        searchimage.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                searchtextField.clearFocus();
            }
        });

        approotdl_topdl.addComponent(searchbar_rootdl);
    }
    public void installTitleBar(String name){
        if(approotdl_topdl == null){
            return;
        }
        if(approotdl_topdl.getChildCount() != 0){
            approotdl_topdl.removeAllComponents();
        }
        DirectionalLayout titlebar_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_titlebar,null,true);
        ((Text) titlebar_rootdl.getComponentAt(0)).setText(name);
        approotdl_topdl.addComponent(titlebar_rootdl);
    }

    public void addTabToTabList(TabList tabList,String name,String tablistname){
        if(tabList == null || name.equals("")){
            return;
        }

        TabList.Tab tab = tabList.new Tab(this.getContext());
        tab.setText(name);
        tabList.addTab(tab);

        if(tablistname.equals("bottomtablist")){
            bottomtabslist.add(tab);
        }
        if(tablistname.equals("firstcenter_tabslist")){
            firstcenter_tabslist.add(tab);
        }
    }

    public void initFirstCenterTabList(TabList tabList,String[] tabnames,String tablistname){
        if(tabList == null){
            return;
        }
        firstcenter_tabslist.clear();
        tabList.removeAllComponents();
        for(int i = 0;i < tabnames.length;i++){
            addTabToTabList(tabList,tabnames[i],tablistname);
        }

        tabList.setName(tablistname);


        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
                firstpage_center_rootdl_PageSlider.setCurrentPage(tabList.getSelectedTabIndex());
            }

            @Override
            public void onUnselected(TabList.Tab tab) {
                DirectionalLayout directionalLayout = (DirectionalLayout)  approotdl_topdl.getComponentAt(0);
                TextField searchtextField = (TextField) directionalLayout.getComponentAt(0);
                searchtextField.clearFocus();
            }

            @Override
            public void onReselected(TabList.Tab tab) {
                //小技巧:
                //这里的当一个tab被重复选中,可以执行诸如刷新页面的操作
                DirectionalLayout directionalLayout = (DirectionalLayout) approotdl_topdl.getComponentAt(0);
                TextField searchtextField = (TextField) directionalLayout.getComponentAt(0);
                searchtextField.clearFocus();
            }
        });
        if(tabList.getTabCount() != 0){
            tabList.selectTabAt(0);
        }
    }
    public void initBottomTabList(TabList tabList,String[] tabnames,String tablistname){
        if(tabList == null){
            return;
        }
        for(int i = 0;i < tabnames.length;i++){
            addTabToTabList(tabList,tabnames[i],tablistname);
        }

        tabList.setName(tablistname);

        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {

                if (tabList.getName().equals(tablistname)) {
                    if (tab.getText().equals("首页")) {
                        installSearchBar();
                        installCenterSubLayout(0);
                        initFirstCenterPageSlider(firstpage_center_rootdl_PageSlider);
                        initFirstCenterTabList(firstpage_center_rootdl_tablist, firstcenter_names, "firstcenter_tabslist");
                        return;
                    }

                    int i = tabList.getSelectedTabIndex();//获取当前选中的tab位置
                    installTitleBar(bottomtabslist.get(i).getText());//将该tab的文本设置为该页的title
                    installCenterSubLayout(i);
                }
            }

            @Override
            public void onUnselected(TabList.Tab tab) {

            }

            @Override
            public void onReselected(TabList.Tab tab) {
                //小技巧:
                //这里的当一个tab被重复选中,可以执行诸如刷新页面的操作
            }
        });
        if(tabList.getTabCount() != 0){
            tabList.selectTabAt(0);
        }
    }

    public void addPagesToPageSliderList(){
        firstcenter_pagesliderslist.clear();
        for(int i = 0;i < firstcenter_names.length;i++){
            DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_pageslider_directionallayout,null,false);
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.setMatrix(FloatsOfColorMatrix.floats[i]);
            directionalLayout.getBackgroundElement().setColorMatrix(colorMatrix);

            firstcenter_pagesliderslist.add(directionalLayout);
        }
    }

    public void initFirstCenterPageSlider(PageSlider pageSlider){
        if(pageSlider == null){
            return;
        }
        addPagesToPageSliderList();

        pageSlider.setPageSwitchTime(50);
        pageSlider.setSlidingPossible(true);
        pageSlider.setReboundEffect(true);

        pageSlider.addPageChangedListener(new PageSlider.PageChangedListener() {
            @Override
            public void onPageSliding(int i, float v, int i1) {

            }

            @Override
            public void onPageSlideStateChanged(int i) {

            }

            @Override
            public void onPageChosen(int i) {
                firstpage_center_rootdl_tablist.selectTabAt(i);
            }
        });
        pageSlider.setProvider(new FirstCenterPgSdProvider(firstcenter_pagesliderslist));
    }

    public void installCenterSubLayout(int n){
        //0-首页,1-动态,2-创作,3-消息,4-我的
        if(approotdl_centerdl == null){
            return;
        }
        if(approotdl_centerdl.getChildCount() != 0){
            approotdl_centerdl.removeAllComponents();
        }
        approotdl_centerdl.removeAllComponents();
        switch(n){
            case 0:
                DirectionalLayout firstpage_center_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_firstpage_center,null,false);
                firstpage_center_rootdl_tablist = (TabList) firstpage_center_rootdl.findComponentById(ResourceTable.Id_firstpage_center_rootdl_tablist);
                firstpage_center_rootdl_PageSlider = (PageSlider) firstpage_center_rootdl.findComponentById(ResourceTable.Id_firstpage_center_rootdl_PageSlider);
                approotdl_centerdl.addComponent(firstpage_center_rootdl);
                break;
            case 1:
                DirectionalLayout dtpage_center_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_dtpage_center,null,false);
                dtpage_center_rootdl_listcontainer = (ListContainer) dtpage_center_rootdl.findComponentById(ResourceTable.Id_dtpage_center_rootdl_listcontainer);
                /************************************示例数据填充***************************/
                commonlistcontaineritem_list.clear();
                for(int i = 0;i < 13;i++){
                    commonlistcontaineritem_list.add(new CommonListContainerItem("榜单排名第"+i+"条!"));
                }
                initCommonListContainer(dtpage_center_rootdl_listcontainer);

                /************************************示例数据填充***************************/
                approotdl_centerdl.addComponent(dtpage_center_rootdl);
                break;
            case 2:
                DirectionalLayout writepage_center_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_writepage_center,null,false);
                Button writepage_center_topddl_nobut,writepage_center_topddl_gobut;
                TextField writepage_center_rootdl_tfd;

                writepage_center_topddl_nobut = (Button) writepage_center_rootdl.findComponentById(ResourceTable.Id_writepage_center_topddl_nobut);
                writepage_center_topddl_gobut = (Button) writepage_center_rootdl.findComponentById(ResourceTable.Id_writepage_center_topddl_gobut);
                writepage_center_rootdl_tfd = (TextField) writepage_center_rootdl.findComponentById(ResourceTable.Id_writepage_center_rootdl_tfd);

                writepage_center_topddl_nobut.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        writepage_center_rootdl_tfd.setText("");
                        writepage_center_rootdl_tfd.clearFocus();
                        toastShow("取消发布!");
                        approotdl_bottomdl_tablist.selectTabAt(0);
                    }
                });
                writepage_center_topddl_gobut.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        if(writepage_center_rootdl_tfd.getText().equals("")){
                            toastShow("内容不能为空!");
                            writepage_center_rootdl_tfd.clearFocus();
                            return;
                        }
                        writepage_center_rootdl_tfd.setText("");
                        writepage_center_rootdl_tfd.clearFocus();
                        toastShow("发布成功!");
                        approotdl_bottomdl_tablist.selectTabAt(0);
                    }
                });

                writepage_center_rootdl_tfd.addTextObserver(new Text.TextObserver() {
                    @Override
                    public void onTextUpdated(String s, int i, int i1, int i2) {

                    }
                });
                approotdl_centerdl.addComponent(writepage_center_rootdl);
                break;
            case 3:
                DirectionalLayout messagepage_center_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_messagepage_center,null,false);
                Image messagepage_center_rootdl_ddl1_agree,messagepage_center_rootdl_ddl1_discuss,messagepage_center_rootdl_ddl1_collection;
                messagepage_center_rootdl_ddl1_agree = (Image) messagepage_center_rootdl.findComponentById(ResourceTable.Id_messagepage_center_rootdl_ddl1_agree);
                messagepage_center_rootdl_ddl1_discuss = (Image) messagepage_center_rootdl.findComponentById(ResourceTable.Id_messagepage_center_rootdl_ddl1_discuss);
                messagepage_center_rootdl_ddl1_collection = (Image) messagepage_center_rootdl.findComponentById(ResourceTable.Id_messagepage_center_rootdl_ddl1_collection);
                messagepage_center_rootdl_listcontainer = (ListContainer) messagepage_center_rootdl.findComponentById(ResourceTable.Id_messagepage_center_rootdl_listcontainer);

                messagepage_center_rootdl_ddl1_agree.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        /************************************示例数据填充***************************/
                        commonlistcontaineritem_list.clear();
                        for(int i = 0;i < 13;i++){
                            commonlistcontaineritem_list.add(new CommonListContainerItem("点赞信息"+i+"条!"));
                        }
                        CommonListContainerProvider.commonListContainerProvider.notifyDataChanged();
                        /************************************示例数据填充***************************/
                    }
                });
                messagepage_center_rootdl_ddl1_discuss.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        /************************************示例数据填充***************************/
                        commonlistcontaineritem_list.clear();
                        for(int i = 0;i < 13;i++){
                            commonlistcontaineritem_list.add(new CommonListContainerItem("评论信息"+i+"条!"));
                        }
                        CommonListContainerProvider.commonListContainerProvider.notifyDataChanged();
                        /************************************示例数据填充***************************/
                    }
                });
                messagepage_center_rootdl_ddl1_collection.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        /************************************示例数据填充***************************/
                        commonlistcontaineritem_list.clear();
                        for(int i = 0;i < 13;i++){
                            commonlistcontaineritem_list.add(new CommonListContainerItem("收藏信息"+i+"条!"));
                        }
                        CommonListContainerProvider.commonListContainerProvider.notifyDataChanged();
                        /************************************示例数据填充***************************/
                    }
                });

                approotdl_centerdl.addComponent(messagepage_center_rootdl);

                commonlistcontaineritem_list.clear();
                initCommonListContainer(messagepage_center_rootdl_listcontainer);

                messagepage_center_rootdl_ddl1_agree.getClickedListener().onClick(messagepage_center_rootdl_ddl1_agree);//默认执行一次点击“点赞”的动作
                break;
            case 4:
                DirectionalLayout mepage_center_rootdl = (DirectionalLayout) LayoutScatter.getInstance(this.getContext()).parse(ResourceTable.Layout_mepage_center,null,false);

                approotdl_centerdl.addComponent(mepage_center_rootdl);

                break;
            default:
                break;
        }


    }

    public void initMSComponents(){
        approotdl_topdl = (DirectionalLayout) findComponentById(ResourceTable.Id_approotdl_topdl);
        approotdl_centerdl = (DirectionalLayout) findComponentById(ResourceTable.Id_approotdl_centerdl);
        approotdl_bottomdl = (DirectionalLayout) findComponentById(ResourceTable.Id_approotdl_bottomdl);

        approotdl_bottomdl_tablist = (TabList) findComponentById(ResourceTable.Id_approotdl_bottomdl_tablist);
    }


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initMSComponents();
        initBottomTabList(approotdl_bottomdl_tablist,bottomnames,"bottomtablist");
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}

  3.6 MainAbility.java

package com.tdtxdcxm.appgeneralframework;

import com.tdtxdcxm.appgeneralframework.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
    }
}

  3.7 MyApplication.java

package com.tdtxdcxm.appgeneralframework;

import ohos.aafwk.ability.AbilityPackage;

public class MyApplication extends AbilityPackage {
    @Override
    public void onInitialize() {
        super.onInitialize();
    }
}

4. XML源代码

  4.1 UI背景XML

   4.1.1 background_ability_main.xml

<?xml version="1.0" encoding="UTF-8" ?>

    

   4.1.2 background_common_directional.xml.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.1.3 background_common_listcontainer_item.xml

<?xml version="1.0" encoding="UTF-8" ?>


    
    

   4.1.4 background_common_subdirectional.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.1.5 background_searchbar_rootdl.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.1.6 background_titlebar_rootdl.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

  4.2 主页与子布局XML

   4.2.1 ability_main.xml

<?xml version="1.0" encoding="utf-8"?>

    
    
    
    
    
        
        
    

   4.2.2 common_listcontainer_item.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.2.3 dtpage_center.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.2.4 firstpage_center.xml

<?xml version="1.0" encoding="utf-8"?>

    
    
    
    

   4.2.5 mepage_center.xml

<?xml version="1.0" encoding="utf-8"?>

    
        
        
        
        
    
    
        
            
            
            
            
            
            
            
            
        
        
            
            
            
            
            
            
            
            
        
        
            
            
            
            
            
            
            
            
        
        
            
            
            
            
            
            
            
            
        
    

   4.2.6 messagepage_center.xml

<?xml version="1.0" encoding="utf-8"?>

    
        
        
        
        
        
        
    
    
    

   4.2.7 pageslider_directionallayout.xml

<?xml version="1.0" encoding="utf-8"?>



   4.2.8 searchbar.xml

<?xml version="1.0" encoding="utf-8"?>

    
    
    
    

   4.2.9 titlebar.xml

<?xml version="1.0" encoding="utf-8"?>

    
    

   4.2.10 writepage_center.xml

<?xml version="1.0" encoding="utf-8"?>

    
        
        
    
    
    

5. 图像资源

  5.1 点赞图标

在这里插入图片描述

  5.2 评论图标

在这里插入图片描述

  5.3 收藏图标

在这里插入图片描述

  5.4 搜索图标(来自鸿蒙官网系统图标下载)

请添加图片描述

6. app截图

请添加图片描述

请添加图片描述

请添加图片描述

请添加图片描述

请添加图片描述

7. app运行视频(本地模拟器运行)

通用app界面框架AppGeneralFrameWork[app通用框架][API V6]