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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?