首页 > 解决方案 > 以编程方式添加开关按钮拇指色调颜色(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);

标签: androidandroid-studio

解决方案


以编程方式,您可以使用:

switch.setThumbTintList(AppCompatResources.getColorStateList(this,R.color.xxxx));

推荐阅读