View(Context context, AttributeSet attrs, int defStyle)
样式无效,怎么回事?? Button newButton = new Button(this, null, R.style.myButtonStyle);
newButton.setText("我是按钮");样式代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myButtonStyle">
<item name="android:layout_width">200px</item>
<item name="android:layout_height">300px</item>
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">20px</item>
</style>
</resources>

解决方案 »

  1.   

    你这个只得到了样式,但是你还没把样式用在Button上面呢?这就不能怪样式在Button上没显示了!
      

  2.   

    Button newButton = new Button(this, null, R.style.myButtonStyle);
    第三个参数用到样式了啊,
      

  3.   

    public View (Context context, AttributeSet attrs, int defStyle) 
    Since: API Level 1 Perform inflation from XML and apply a class-specific base style. This constructor of View allows subclasses to use their own base style when they are inflating. For example, a Button class's constructor would call this version of the super class constructor and supply R.attr.buttonStyle for defStyle; this allows the theme's button style to modify all of the base view attributes (in particular its background) as well as the Button class's attributes.
      

  4.   

    楼上的前辈我这样做是原来的样式了
    Button newButton = new Button(this, null, android.R.attr.buttonStyle);我想要实现的功能是改变自带Button类的原来样式,用我继承系统的样式啊
      

  5.   

    好像style要集成基类Button吧,你这样Button的默认动作都没有