如何在Kotlin中实现带步骤指示器与文字的横向分步进度条
实现横向两步进度条
下面是一个符合需求的实现方案,包含当前步骤指示器和步骤文字:
HTML 结构
<div class="step-progress"> <div class="progress-track"> <div class="progress-fill"></div> </div> <div class="steps"> <div class="step active"> <div class="step-indicator">1</div> <div class="step-label">第一步</div> </div> <div class="step"> <div class="step-indicator">2</div> <div class="step-label">第二步</div> </div> </div> </div>
CSS 样式
/* 进度条容器 */ .step-progress { width: 80%; margin: 30px auto; position: relative; } /* 进度轨道 */ .progress-track { height: 4px; background-color: #e0e0e0; border-radius: 2px; position: absolute; top: 20px; left: 0; right: 0; z-index: 1; } /* 进度填充 */ .progress-fill { height: 100%; background-color: #2196f3; border-radius: 2px; width: 0%; transition: width 0.3s ease; } /* 步骤容器 */ .steps { display: flex; justify-content: space-between; position: relative; z-index: 2; } /* 步骤项 */ .step { display: flex; flex-direction: column; align-items: center; } /* 步骤指示器 */ .step-indicator { width: 40px; height: 40px; border-radius: 50%; background-color: #e0e0e0; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #666; transition: all 0.3s ease; } /* 当前激活的步骤 */ .step.active .step-indicator { background-color: #2196f3; color: white; } /* 步骤文字 */ .step-label { margin-top: 8px; font-size: 14px; color: #666; } .step.active .step-label { color: #2196f3; font-weight: bold; }
使用说明
切换步骤时,给对应的.step元素添加active类,同时调整.progress-fill的width属性:
- 第一步激活时,设置
width: 0% - 第二步激活时,设置
width: 100%
你可以根据实际需求调整颜色、尺寸、间距等样式参数,比如修改#2196f3为你需要的主题色,调整.step-progress的width来适配布局。
内容的提问来源于stack exchange,提问作者Omar Khaleel
相关产品推荐
相关产品推荐

