Can I make an Android button template?

前端 未结 4 2106
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 00:32

I have several buttons in my current app. They are all identical except for their text and a tag. The main.xml would be a lot nicer if I didn\'t have to repeat all the button

4条回答
  •  孤城傲影
    2021-02-09 01:25

    You can make a custom view that extends button and sets all the things that is repeating. Then you can use it as you described, but with a fully qualified name, not just shortname.

    class MyButton extends Button {
        public MyButton() {
            // Set the values you want
        }
    }
    

    And in XML:

    
    

提交回复
热议问题