ability_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<RoundProgressBar
ohos:id="$+id:rpb"
ohos:height="300vp"
ohos:width="300vp"
ohos:max="100"
ohos:min="0"
ohos:progress="0"
ohos:progress_color="#FFDE2B2B"
ohos:progress_hint_text="0%"
ohos:progress_hint_text_color="#FF000000"
ohos:progress_hint_text_size="50vp"
ohos:progress_width="20vp"
/>
</DirectionalLayout>
MainAbilitySlice.java代码:
package com.example.progressbarapplication.slice;
import com.example.progressbarapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.RoundProgressBar;
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
RoundProgressBar rpb;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
//1.找到进度条组件
rpb = (RoundProgressBar) findComponentById(ResourceTable.Id_rpb);
//2.绑定单击事件
rpb.setClickedListener(this);
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
@Override
public void onClick(Component component) {
int progresss = rpb.getProgress();
if (progresss >= 100) {
return;
}
progresss += 5;
rpb.setProgressValue(progresss);
rpb.setProgressHintText(progresss + "%");
}
}
效果: