鸿蒙开源组件——开关按钮

jacksky
发布于 2021-7-21 18:34
3377浏览
0收藏

SwitchButton

SwitchButton is An beautiful+lightweight+custom-style-easy switch widget

#效果图鸿蒙开源组件——开关按钮-鸿蒙开发者社区

集成引用

方法一: 1、添加har包到libs文件夹内 2、在entry的gradle内添加如下代码: dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) }

方法二: 1、配置中心仓: repositories { mavenCentral() } 2、在entry的gradle内添加如下代码: dependencies { implementation 'io.openharmony.tpc.thirdlib:SwitchButton:1.0.2' }

entry运行要求

通过DevEco studio,并下载HarmonySDK 将项目中的build.gradle文件中dependencies→classpath版本改为对应的版本(即你的IDE新建项目中所用的版本)

示例

    <com.suke.widget.SwitchButton
            ohos:left_margin="20vp"
            ohos:width="200vp"
            ohos:height="60vp"
            ohos:id="$+id:btn_switch1"
            />
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

 

    SwitchButton switchButton1 = (SwitchButton) findComponentById(ResourceTable.Id_btn_switch1);
            switchButton1.setEnableEffect(true);
            switchButton1.isChecked();
            switchButton1.setShadowEffect(true);
            switchButton1.setShadowColor(0x4d888888);
            switchButton1.setShadowRadius(6);
            switchButton1.setChecked(true);
            switchButton1.setUncheckColor(0xcc888888);
            switchButton1.setBorderWidth(3);
            switchButton1.setEffectDuration(100);
            switchButton1.setShowIndicator(false);
            switchButton1.setOnCheckedChangeListener((view, isChecked) -> {

        });

   More Style:

    /**
     * 背景底色
     */
    private int background;
    /**
     * 背景关闭颜色
     */
    private int uncheckColor;
    /**
     * 背景打开颜色
     */
    private int checkedColor;
    /**
     * 边框宽度px
     */
    private int borderWidth;

    /**
     * 打开指示线颜色
     */
    private int checkLineColor;
    /**
     * 打开指示线宽
     */
    private int checkLineWidth;
    /**
     * 打开指示线长
     */
    private float checkLineLength;
    /**
     * 关闭圆圈颜色
     */
    private int uncheckCircleColor;
    /**
     * 关闭圆圈线宽
     */
    private int uncheckCircleWidth;
    /**
     * 关闭圆圈位移X
     */
    private float uncheckCircleOffsetX;
    /**
     * 关闭圆圈半径
     */
    private float uncheckCircleRadius;
    /**
     * 打开指示线位移X
     */
    private float checkedLineOffsetX;
    /**
     * 打开指示线位移Y
     */
    private float checkedLineOffsetY;
    /**
     * Color for button when it's uncheck
     */
    private int uncheckButtonColor;
    /**
     * Color for button when it's check
     */
    private int checkedButtonColor;

    /**
     * 是否选中
     */
    private boolean isChecked;
    /**
     * 是否启用动画
     */
    private boolean enableEffect;
    /**
     * 是否启用阴影效果
     */
    private boolean shadowEffect;
    /**
     * 是否显示指示器
     */
    private boolean showIndicator = true;

    /**
     * 阴影半径
     */
    private int shadowRadius;

    /**
     * 阴影颜色
     */
    private int shadowColor;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.

License

MIT, See the [LICENSE] file for details.

SwitchButton-master.zip 239.07K 18次下载
已于2021-7-21 18:34:03修改
收藏
回复
举报


回复
    相关推荐