Create android buttons programmatically using XML layout as template

落爺英雄遲暮 提交于 2019-12-05 04:43:06

Have you thought of making a layout that is just the button with the applied XML styles and then inflating it into your linear layout?

something like:

inflater.inflate(R.layout.StyledButton, MyLinearLayout, true);

xml for your button under /res/layout/my_button_layout.xml

<Button xmlns:android="http://schemas.android.com/apk/res/android"
   ... />

code in your activity

myButton = (Button)inflate.inflate(R.layout.my_button_layout, null);
myView.addView(myButton);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!