当前位置: 首页 > news >正文

给安卓设置背景色的时候保持默认按钮样式(关于使用setBackgroundColor导致丢失默认按钮样式的问题)

给安卓设置背景色的时候保持默认按钮样式(关于使用setBackgroundColor导致丢失默认按钮样式的问题)

核心api

Button.setBackgroundTintList(ColorStateList);
    void initPatterns(LinearLayout PatternsRoot){for(int i=0;i<512;i++){Button patternButton = new Button(PianoRollActivity.this);patternButton.setText(String.valueOf(i));patternButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view){for(int i=0;i<PatternsRoot.getChildCount();i++){
                        PatternsRoot.getChildAt(i).setBackgroundTintList(ColorStateList.valueOf(Colors.defaultButtonColor));}
                    patternButton.setBackgroundTintList(ColorStateList.valueOf(Colors.orange));}});PatternsRoot.addView(patternButton);}}
}

Colors.java

package com.xsh.opensltest.style;import android.graphics.Color;public class Colors
{public static int orange = Color.rgb(255,165,0);public static int keyBlackColor = Color.BLACK;public static int noteColor = Color.RED;public static int keyWhiteColor= Color.WHITE;;// 升音public static int bgBlackColor = Color.GRAY;public static int bgWhiteColor = Color.WHITE;public static int defaultButtonColor = Color.LTGRAY;
}

 

http://www.rkmt.cn/news/30708.html

相关文章:

  • 分片上传与断点续传实现详解
  • Kanass入门到实战(6) - 如何进行缺陷管理 - 指南
  • 数据处理方法汇总
  • 2025 年 10 月展示柜厂家最新推荐,技术实力与市场口碑深度解析!
  • 2025年10月益生菌品牌推荐榜:全维度对比与榜单解读
  • 2025年10月美容仪品牌推荐:无创无痛对比评测榜
  • 2025年10月中国遗产继承律师推荐榜:五强对比全解析
  • php特性
  • 2025年10月深圳近视手术医生推荐榜:五强对比与口碑评价
  • php_sha1函数特性
  • php非法参数
  • php原生类的使用
  • 2025 年 10 月仿石漆厂家最新推荐,精准检测与稳定性能深度解析
  • 下午选歌
  • 分治算法在查找第k小元素中的应用与分析
  • 2025年10月中国装饰公司对比榜:十家口碑与实力排行
  • 2025年10月电竞显示器品牌评价榜:五强对比与选购要点
  • 2025年10月食品展会推荐榜:NHNE领衔五大展会对比评测
  • 2025年10月连锁酒店排行榜推荐:丽柏丽怡领衔对比评测榜
  • 关于克服 libwebsockets 库编译时遇到的困难的实用的方法:
  • 2025年10月暖风机口碑榜:主流机型对比与选购避坑指南
  • LazyLLM学习:使用提示词工程+RAG创建AI女友
  • 详细介绍:K8s StorageClass配置实战:从入门到精通
  • 2025 年 10 月铜材切削液厂家最新推荐,精准检测与稳定性能深度解析
  • 实用指南:proxy_pass和location匹配路径的拼接逻辑
  • 【System Beats!】第四章 处理器体系结构
  • 申威 SW-64 架构安装 MySQL 8.0.18 (KY10系统 RPM包) 步骤指南
  • java learning
  • 【11】C实战篇——C语言 【scanf、printf、fprintf、fscanf、sprintf、sscanf】的区别 - 详解
  • Correlation inequality小记