android - How to add button tint programmatically -


in new appcompat library, can tint button way:

       <button             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="@string/follow"             android:id="@+id/button_follow"             android:backgroundtint="@color/blue_100"             /> 

how can set tint of button programmatically in code? i'm trying implement conditional coloring of button based on user input

according documentation related method android:backgroundtint setbackgroundtintlist(colorstatelist list)

update

follow link know how create color state list resource.

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" >     <item         android:color="#your_color_here" /> </selector> 

then load using

setbackgroundtintlist(contextinstance.getresources().getcolorstatelist(r.color.your_xml_name)); 

where contextinstance instance of context


using appcompart

btntag.setsupportbuttontintlist(contextcompat.getcolorstatelist(activity.this, r.color.colorprimary)); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -