android - 以编程方式添加开关按钮拇指色调颜色(ANDROID STUDIO)
问题描述
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumbTint="@color/red"/>
我想在 Java 中为我的开关添加红色拇指色调
下面是我在java中的代码
Switch switch_btn=new Switch(edit_turf.this);
switch_btn.setOnClickListener(edit_turf.this)
switch_btn.setId(i);
relativeLayout.addView(switch_btn);
解决方案
以编程方式,您可以使用:
switch.setThumbTintList(AppCompatResources.getColorStateList(this,R.color.xxxx));
推荐阅读
- r - Quantmod Heikin-Ashi 绘图不可用
- json - laravel 4 输出 json 顺序描述
- css - 如何使用 data-* 作为省略号元素的工具提示
- mysql - 为什么从视图中检索数据与该视图的基础选择时存在性能差异
- javascript - 匹配 JSON 对象中的键/值
- r - 如何在 R 中创建时间序列?
- python - 将多个函数应用于返回多个数据帧的熊猫 groupby 应用?
- swift - 如何在 Swift 中请求游戏的首字母缩写
- swift - 如何将导航栏后退按钮图像设置为默认符号?
- spring-boot - spring boot 在 URL 中定义的名称为“WDSDataSource”的无效 bean 定义“