Android画个圆点状态灯

编程入门 行业动态 更新时间:2024-10-17 11:21:59

Android画个<a href=https://www.elefans.com/category/jswz/34/1717407.html style=圆点状态灯"/>

Android画个圆点状态灯

1、创建一个 XML 文件在 res/drawable 目录下(默认为黑色)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android=""android:shape="oval"><solid android:color="#000000" /><sizeandroid:width="24dp"android:height="24dp" />
</shape>

2、创建布局

// 创建一个水平的LinearLayout来包含“故障”文本和圆点图片final LinearLayout statusLayout = new LinearLayout(context);statusLayout.setOrientation(LinearLayout.HORIZONTAL);// 添加圆点图片final ImageView dotImage = new ImageView(context);LinearLayout.LayoutParams dotImageParams = new LinearLayout.LayoutParams(10,  // 设置宽度为10dp10   // 设置高度为10dp);dotImageParams.setMargins(0, 0, 5, 0);dotImage.setLayoutParams(dotImageParams);// 添加圆点图片到statusLayoutdotImage.setImageResource(R.drawable.circle);statusLayout.addView(dotImage);// 添加文本final TextView statusText = new TextView(context);textView.setWidth(100);// 添加文本到statusLayoutstatusLayout.addView(statusText);textViews[index] = statusText;dotImages[index] = dotImage;

3、调接口后更新状态

int idleColor = Color.parseColor(color);dotImages[index].setColorFilter(new PorterDuffColorFilter(idleColor, PorterDuff.Mode.SRC_IN));textViews[index].setText(name);

更多推荐

Android画个圆点状态灯

本文发布于:2023-11-15 11:00:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:圆点   状态   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!