16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating_第1张图片

 16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating_第2张图片

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating_第3张图片

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating 

ability_main.xml




    
    
    
    

 16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating_第4张图片

 

MainAbilitySlice.java

rating.setGrainSize(1f); //最小的控制粒度
rating.setScore(6f); //当前的评级分数
rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Rating;
import ohos.agp.components.element.PixelMapElement;
import ohos.global.resource.Resource;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Rating rating = (Rating) findComponentById(ResourceTable.Id_rating_sce);
        rating.setGrainSize(1f); //最小的控制粒度
        rating.setScore(6f); //当前的评级分数
        rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
        Resource resource = null;
        try
        {
            //设置评级分背景:点亮的五角星
            rating.setFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
            //rating.setHalfFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
            rating.setUnfilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3a)));
        }
        catch (Exception e)
        {

        }
    }

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

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

 

你可能感兴趣的:(harmonyos,java,华为)