Himanshu Garg
Himanshu Garg

Reputation: 1

Add switch button thumb tint color programmaically (ANDROID STUDIO)

<Switch
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:thumbTint="@color/red"/>                 

I want to add red thumb tint color to my switch in java

Below is my code in java

Switch switch_btn=new Switch(edit_turf.this);
              switch_btn.setOnClickListener(edit_turf.this)
              switch_btn.setId(i);
              relativeLayout.addView(switch_btn);

Upvotes: 0

Views: 399

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364770

Programmatically you can use:

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

Upvotes: 1

Related Questions