如果您想设置从代码创建的按钮的样式,您必须执行以下操作;Buttonbtn=newButton(mActivity,null,R.attr.someattribute);在attrs.xml中,你设置了一个引用在styles.xml中,你定义了一个主题@style/someStylestyles.xml中后期定义为example2pxfill_parent@drawable/actionbar_compat_separator这是可行的,根据我的理解,这是在Android代码中设置View样式的方法。这似乎过于复杂。按钮的第三个构造函数Argument很容易接受样式IDR.style.