android - How to programmatically setting style attribute in a view -
i'm getting view xml code below:
button view = (button) layoutinflater.from(this).inflate(r.layout.section_button, null); i set "style" button how can in java since want use several style each button use.
generally can't change styles programmatically; can set of screen, or part of layout, or individual button in xml layout using themes or styles. themes can, however, be applied programmatically.
there such thing statelistdrawable lets define different drawables each state button can in, whether focused, selected, pressed, disabled , on.
for example, button change colour when it's pressed, define xml file called res/drawable/my_button.xml directory this:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/btn_pressed" /> <item android:state_pressed="false" android:drawable="@drawable/btn_normal" /> </selector> you can apply selector button setting property android:background="@drawable/my_button".
Comments
Post a Comment