Friday, April 20, 2012

How to extend an Android button and use an xml layout file

I'm trying to extend the android button class and have it use an xml layout file.



The reason I want to use an xml layout file is that my button needs to use a style and as far as I know, there isn't a way to set style programatically.




public class BuyButton extends Button { ... }




<?xml version="1.0" encoding="utf-8"?>  
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/customButton"
/>


so that I can call:



new BuyButton(activity);


and have it create a button that has the style applied to it.



(I'm also open to other ways of getting the same result)





No comments:

Post a Comment