HarmonyOS 如何实现左侧竖列导航栏且可以item点击展开搜索效果

左侧为可收起的导航栏,有点击选中效果;右侧为列表

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

可以参考下述demo:

import { TreeController, TreeListener, TreeListenerManager, TreeListenType, NodeParam, TreeView, CallbackParam } from '@ohos.arkui.advanced.TreeView'
@Entry
@Component
struct TreeViewDemo {
  private treeController: TreeController = new TreeController();
  private treeListener: TreeListener = TreeListenerManager.getInstance().getTreeListener();
  @State clickNodeId: number = 0;

  aboutToDisappear(): void {
    this.treeListener.off(TreeListenType.NODE_CLICK, undefined);
    this.treeListener.off(TreeListenType.NODE_ADD, undefined);
    this.treeListener.off(TreeListenType.NODE_DELETE, undefined);
    this.treeListener.off(TreeListenType.NODE_MOVE, undefined);
  }

  aboutToAppear(): void {
    this.treeListener.on(TreeListenType.NODE_CLICK, (callbackParam: CallbackParam) => {
      this.clickNodeId = callbackParam.currentNodeId;
    })
    this.treeListener.on(TreeListenType.NODE_ADD, (callbackParam: CallbackParam) => {
      this.clickNodeId = callbackParam.currentNodeId;
    })
    this.treeListener.on(TreeListenType.NODE_DELETE, (callbackParam: CallbackParam) => {
      this.clickNodeId = callbackParam.currentNodeId;
    })
    this.treeListener.once(TreeListenType.NODE_MOVE, (callbackParam: CallbackParam) => {
      this.clickNodeId = callbackParam.currentNodeId;
    })

    let nodeParam: NodeParam = { parentNodeId:-1, currentNodeId: 1, isFolder: true,
      primaryTitle: "分析",
    };
    this.treeController
      .addNode(nodeParam)
      .addNode({parentNodeId:1, currentNodeId: 2, isFolder: false, primaryTitle: "早间提示" })
      .addNode({parentNodeId:1, currentNodeId: 3, isFolder: false, primaryTitle: "热点聚焦" })
      .addNode({parentNodeId:1, currentNodeId: 4, isFolder: false, primaryTitle: "每日评述" })
      .addNode({parentNodeId:1, currentNodeId: 5, isFolder: false, primaryTitle: "每周评述" })
      .addNode({ parentNodeId:-1, currentNodeId: 36, isFolder: false, primaryTitle: "报告" })
      .buildDone();
    this.treeController.refreshNode(-1, "父节点", "子节点");
  }

  build() {
    Column(){
      SideBarContainer(SideBarContainerType.Embed)
      {
        TreeView({ treeController: this.treeController })
        Row() {
          Divider().vertical(true).strokeWidth(1).color(0x000000).lineCap(LineCapStyle.Round)
          Column({ space: 30 }) {
            Text('ClickNodeId=' + this.clickNodeId).fontSize('16fp')
          }.height('100%').width('70%').alignItems(HorizontalAlign.Center)
        }
      }
      .sideBarWidth(150)
      // .minSideBarWidth(50)
      // .maxSideBarWidth(300)
      .focusable(true)
      .showControlButton(false)
      .showSideBar(true)

    }
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
如何实现搜索历史记录
978浏览 • 1回复 待解决
navigation 导航支持毛玻璃效果吗?
779浏览 • 1回复 待解决
如何实现按钮的点击效果
477浏览 • 2回复 待解决
Navigation如何隐藏导航
2197浏览 • 1回复 待解决
如何获取状态导航高度?
260浏览 • 0回复 待解决
如何获取状态导航高度
2926浏览 • 1回复 待解决
HarmonyOS 导航主题色如何配置
76浏览 • 1回复 待解决
HarmonyOS 如何获取底部导航高度?
33浏览 • 1回复 待解决
如何设置状态导航的颜色
2992浏览 • 1回复 待解决
鸿蒙如何获取导航和状态高度
11441浏览 • 1回复 待解决