title: Android programical set attribute for xml widgets
body: <p>in application i can simply define <code>attr.xml</code> into <code>values</code> and use that into design layout. but i can not set this attributes programical into widgets, for example i have this attribute:</p>
  
  <pre><code>&lt;declare-styleable name="ButtonTextStyle"&gt;
      &lt;attr name="font_button"&gt;
          &lt;enum name="consolas"      value="0" /&gt;
          &lt;enum name="times"    value="1" /&gt;
      &lt;/attr&gt;
  &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>and i can use this attribute into xml by:</p>
  
  <pre><code>&lt;com.sample.app.Widgets.ButtonTextStyle
      android:id="@+id/btn_way_bill_click"
      android:layout_width="fill_parent"
      app:font_button="consolas"&gt;
  </code></pre>
  
  <p>now i'm define some Button programical into project and i want to use <code>consolas</code> font defined into <code>font_button</code> by:</p>
  
  <pre><code>button.setTextAppearance(context, R.attr.font_button);
  </code></pre>
  
  <p>but i get error for this code and i can not resolve problem, i'm define custom class extends from Button like with this:</p>
  
  <pre><code>public class ButtonTextStyle extends Button {
      private Context mContext;
      public ButtonTextStyle(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          mContext = context;
          init(attrs, defStyle);
      }
  
      public ButtonTextStyle(Context context, AttributeSet attrs) {
          super(context, attrs);
          mContext = context;
          init(attrs,-1);
      }
  
      public ButtonTextStyle(Context context) {
          super(context);
          mContext = context;
          init(null,-1);
      }
  
      private void init(AttributeSet attrs,int defStyle) {
          if (!isInEditMode()) {
              TypedArray a = mContext.obtainStyledAttributes(attrs,R.styleable.ButtonTextStyle, defStyle, 0);
              String str = a.getString(R.styleable.ButtonTextStyle_font_button);
              switch (Integer.parseInt(str)) {
                  case 0:
                      str = "fonts/consolas.ttf";
                      break;
                  case 1:
                      str = "fonts/times.ttf";
                      break;
              }
              setTypeface(FontManager.getInstance(getContext()).loadFont(str));
          }
      }
  }
  </code></pre>
  
  <p><strong>PROBLEM:</strong></p>
  
  <pre><code>Expected resource of type style
  </code></pre>
  
  <p>and i can not set for example enum to widgets like with set <code>times</code> font</p>
  
  <p><strong>HOW to</strong> set programical this custom class with attribute defined into <code>attr.xml</code> </p>
  
  <p><strong>UPDATED:</strong>
  my class to add button is below method. i want to set font for it programically:</p>
  
  <pre><code>private void addButton(final CDialog owner, final Dialog dialog, final DialogButton dlgBtn) {
      LinearLayout linearLayout = (LinearLayout) dialog.findViewById(R.id.tsw__layerButton);
      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 70);
      //layoutParams.setMargins(11, 0, 8, 0);
  
      Button button = new Button(context);
      if (buttonTheme != -1) {
          button.setBackgroundResource(buttonTheme);
      }
      button.setPadding(0,2,0,0);
      button.setGravity(Gravity.CENTER);
      button.setText(buttonMsg[dlgBtn.ordinal()]);
      button.setTextSize(14);
      button.setTextColor(G.context.getResources().getColor(R.color.white_text));
      button.setWidth(dpToPx(buttonWidth));
      //button.setHeight(dpToPx(32));
      button.setLayoutParams(layoutParams);
  
      button.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              dialog.dismiss();
              if (dialogListener != null) {
                  dialogListener.onCloseDialog(owner, dlgBtn);
              }
          }
      });
      linearLayout.addView(button);
  }
  </code></pre>