Android 以编程方式添加按钮不符合文本颜色

Android 以编程方式添加按钮不符合文本颜色,android,xml,button,themes,Android,Xml,Button,Themes,我有一个按钮样式如下: <style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button"> <!-- ORIGINAL: <item name="android:background">@drawable/apptheme_btn_default_holo_light</item> --> <item name="android:backgro

我有一个按钮样式如下:

<style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
      <!-- ORIGINAL: <item name="android:background">@drawable/apptheme_btn_default_holo_light</item> -->
      <item name="android:background">@drawable/x_button_background</item>
      <item name="android:textColor">@drawable/x_button_text</item>
      <item name="android:textSize">@dimen/master_fontsize_mid</item>
      <item name="android:paddingLeft">@dimen/button_padleft</item>
      <item name="android:paddingRight">@dimen/button_padright</item>
      <item name="android:singleLine">true</item>
  </style>
<item name="android:buttonStyle">@style/ButtonAppTheme</item>
背景可绘制渲染效果很好,但文本是白色的,而不是预期的可绘制(灰色和红色,取决于状态)。如何确保以编程方式添加的按钮完全符合此样式?

使用以下代码:

 <Button
     android:id="@+id/button1"
     style="@style/ButtonAppTheme"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Button" />

尝试以这种方式初始化按钮:btn=newbutton(activity,null,R.style.ButtonAppTheme)@Hareshchelana如果我以这种方式创建按钮,我甚至无法获得可绘制的边框。android.widget.button似乎没有setStyle方法。问题是以编程方式添加按钮,而不是通过xml。这是上面@Hareshchelana建议的。它不起作用。此外,我还尝试了应用程序和基础上下文。
 <Button
     android:id="@+id/button1"
     style="@style/ButtonAppTheme"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Button" />
Button b = new Button(getApplicationContext(), null, R.style.ButtonAppTheme);