LiTtleBayReal 2015-08-31 04:15 采纳率: 0%
浏览 1793

自定义roundProgressBar,在xml中定义组件属性,无法生效

我从网上找到了自定义roundProgressBar的代码,使用之后,发现在xml中定义组建的属性没有作用,生成的roundProgressBar只是使用了默认配置

attributes:

<!--
max 最大进度
startAngle 进度从圆环的哪个角度开始走
backColor 圆环内部的填充色
roundColor 圆环的颜色
roundProgressColor 圆环进度的颜色
roundWidth 圆环宽度
textColor 中心文字的颜色
textSize 中心文字的大小
textIsDisplayable 中心文字是否显示
style = 0/1 进度的风格,实心或者空心
-->















roundProgressBar中获取定义属性并赋值:
TypedArray mTypedArray = context.obtainStyledAttributes(attrs,
R.styleable.RoundProgressBar);

    //获取自定义属性和默认值,第一个参数是从用户属性中得到的设置,如果用户没有设置,那么就用默认的属性,即:第二个参数
    //圆环的颜色
    roundColor = mTypedArray.getColor(bm.org.uidemo.R.styleable.RoundProgressBar_roundColor, Color.parseColor("#f9e0e1"));
    //圆环进度条的颜色
    roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, Color.parseColor("#ef7b55"));
    //文字的颜色
    textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.parseColor("#be7e77"));
    //文字的大小
    textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 20);
    //圆环的宽度
    roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 10);
    //最大进度
    max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);
    //是否显示中间的进度
    textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true);
    //进度的风格,实心或者空心
    style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0);
    //进度开始的角度数
    startAngle = mTypedArray.getInt(R.styleable.RoundProgressBar_startAngle, -90);
    // 圆形颜色
    backColor = mTypedArray.getColor(R.styleable.RoundProgressBar_backColor, Color.parseColor("#f8f8f8"));
    mTypedArray.recycle();


            xml中的定义代码:
        <bm.org.uidemo.RoundProgressBar
    android:id="@+id/investment_RoundProgressBar"
    android:layout_width="38dip"
    android:layout_height="71dip"
    android:layout_marginTop="15dip"
    android:layout_marginRight="20dip"
    android:layout_alignParentRight="true"

    android_custom:backColor="#f8f8f8"
    android_custom:startAngle="0"
    android_custom:roundColor="#000000"
    android_custom:roundProgressColor="#ffffff"

    android_custom:roundWidth="90dp"
    android_custom:textColor="#be7e77"
    android_custom:textSize="20sp"

    />

            能有大大告诉我为啥设置没有生效吗??
  • 写回答

2条回答 默认 最新

  • MrCoder_Z 2016-03-18 08:50
    关注

    这个东西能不能通过代码动态设置颜色

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器