title: Android customly created xml button is not showing up in preview
body: <p>I have created a button with custom attributes (actually a linear layout, which has an ImageView and a TextView, and functions like a button). <strong>The problem is that when I try to implement this custom button in the xml layout definiton for an acitivty, it isn't displayed</strong>. How can I fix this?</p>
  
  <p><strong><em>FacebookCustomButton</em></strong></p>
  
  <pre><code>package com.android.neuron.custombuttons;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.graphics.Typeface;
  import android.graphics.drawable.Drawable;
  import android.util.AttributeSet;
  import android.view.Gravity;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class FacebookCustomButton extends LinearLayout {
      private Context context;
  
      private ImageView iconView;
      private TextView textView;
  
      private String iconPath;
      private Drawable iconResource;
      private String textSource;
  
      private int iconWidth;
      private int iconHeight;
      private int iconGravity = 0x11; //Gravity.CENTER
      private int iconMarginStart;
      private int iconMarginEnd;
      private int iconMarginTop;
      private int iconMarginBottom;
  
      private int textGravity = 0x11; //center
      private int textSize;
      private int textColor;
  
  
  
      public FacebookCustomButton(Context context) {
          super(context);
          this.context = context;
  
          initializeButton();
      }
  
      public FacebookCustomButton(Context context, AttributeSet attrs) {
          super(context, attrs);
          initAttrs(context, attrs);
  
          initializeButton();
      }
  
      public FacebookCustomButton(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          initAttrs(context, attrs);
  
          initializeButton();
      }
  
      void initAttrs(Context context, AttributeSet attrs) {
          if(attrs!=null) {
              TypedArray attributeArray = context.obtainStyledAttributes(attrs, R.styleable.FacebookCustomButton);
  
              iconResource = attributeArray.getDrawable(R.styleable.FacebookCustomButton_icon_resource);
  
              String text = attributeArray.getString(R.styleable.FacebookCustomButton_text_source);
              if(text==null) { //no fb textView attribuute
                  text = attributeArray.getString(R.styleable.FacebookCustomButton_android_text);
              }
              textSource = text;
  
              iconWidth = (int) attributeArray.getDimension(R.styleable.FacebookCustomButton_icon_width, Constants.fbButton_icon_default_width);
              iconHeight = (int) attributeArray.getDimension(R.styleable.FacebookCustomButton_icon_height, Constants.fbButton_icon_default_height);
              iconGravity = attributeArray.getInt(R.styleable.FacebookCustomButton_icon_gravity, Constants.fbButton_icon_default_gravity);
  
              iconMarginStart = attributeArray.getInt(R.styleable.FacebookCustomButton_icon_marginStart, Constants.fbButton_icon_default_margin_start);
              iconMarginEnd = attributeArray.getInt(R.styleable.FacebookCustomButton_icon_marginEnd, Constants.fbButton_icon_default_margin_end);
              iconMarginTop = attributeArray.getInt(R.styleable.FacebookCustomButton_icon_marginTop, Constants.fbButton_icon_default_margin_top);
              iconMarginBottom = attributeArray.getInt(R.styleable.FacebookCustomButton_icon_marginBottom, Constants.fbButton_icon_default_margin_bottom);
  
              textGravity = attributeArray.getInt(R.styleable.FacebookCustomButton_text_gravity, Constants.fbButton_icon_default_gravity);
              textSize = (int) attributeArray.getDimension(R.styleable.FacebookCustomButton_text_size, Constants.fbButton_text_size);
  
              String textFontFamily = attributeArray.getString(R.styleable.FacebookCustomButton_text_font);
              Typeface font = Typeface.createFromAsset(context.getAssets(), textFontFamily);
              textView.setTypeface(font);
  
              textColor = attributeArray.getColor(R.styleable.FacebookCustomButton_text_color, getResources().getColor(R.color.fb_defaultColor));
  
          }
      }
  
      /**
       * Initalizes the button:
       *   - the container (linear layout)
       *   - the iconView view
       *   - the textView view
       */
      private void initializeButton() {
          initializeButtonContainer();
          iconView = initializeIconView();
          textView = initializeTextView();
      }
  
      private void initializeButtonContainer() {
          this.setOrientation(LinearLayout.HORIZONTAL);
  
          if(this.getLayoutParams() == null) {
              LayoutParams containerParams = new LayoutParams(LayoutParams.WRAP_CONTENT, Constants.fbButton_default_height);
  
              containerParams.setMargins(Constants.fbButton_default_margin_start,
                      Constants.fbButton_default_margin_top,
                      Constants.fbButton_default_margin_end,
                      Constants.fbButton_default_margin_bottom);
  
              this.setLayoutParams(containerParams);
          }
  
          this.setGravity(Gravity.CENTER);
  
          this.setBackground(context.getDrawable(R.drawable.background_facebook_sign_up_button));
      }
  
      private TextView initializeTextView() {
          if(textSource == null) {
              textSource = context.getResources().getString(R.string.fbButton_default_text_source);
          }
  
          TextView textView = new TextView(context);
          textView.setText(textSource);
  
          textView.setGravity(textGravity);
          textView.setTextColor(textColor);
          textView.setTextSize(textSize);
          textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  
          /*
          Typeface font = Typeface.createFromAsset(context.getAssets(), Constants.default_font_path);
          textView.setTypeface(font);
          */
  
          return textView;
      }
  
      private ImageView initializeIconView() {
          if(iconResource != null) {
              ImageView iconView = new ImageView(context);
              iconView.setImageDrawable(iconResource);
  
              LayoutParams iconViewParams = new LayoutParams(iconWidth, iconHeight);
              iconViewParams.gravity = iconGravity;
              iconViewParams.setMarginStart(iconMarginStart);
              iconViewParams.setMarginEnd(iconMarginEnd);
  
              iconView.setLayoutParams(iconViewParams);
  
              return iconView;
          } else {
              System.out.println("[Neuron.custombuttons.FCB]: Error getting iconView resource! Reutnring null.");
              return null;
          }
      }
  }
  </code></pre>
  
  <p><strong><em>attrs.xml</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;declare-styleable name="FacebookCustomButton"&gt;
          &lt;!-- Default Android attrs --&gt;
          &lt;attr name="android:enabled" /&gt;
          &lt;attr name="android:text" /&gt;
          &lt;attr name="android:textSize" /&gt;
          &lt;attr name="android:textAllCaps" /&gt;
          &lt;attr name="android:textStyle" /&gt;
          &lt;attr name="android:fontFamily" /&gt;
  
          &lt;attr name="icon_width" format="dimension"/&gt;
          &lt;attr name="icon_height" format="dimension"/&gt;
  
          &lt;attr name="icon_gravity" format="enum"&gt;
              &lt;enum name="top" value="0x30" /&gt;
              &lt;enum name="bottom" value="0x50" /&gt;
              &lt;enum name="left" value="0x03" /&gt;
              &lt;enum name="right" value="0x05" /&gt;
              &lt;enum name="center_vertical" value="0x10" /&gt;
              &lt;enum name="fill_vertical" value="0x70" /&gt;
              &lt;enum name="center_horizontal" value="0x01" /&gt;
              &lt;enum name="fill_horizontal" value="0x07" /&gt;
              &lt;enum name="center" value="0x11" /&gt;
              &lt;enum name="fill" value="0x77" /&gt;
              &lt;enum name="clip_vertical" value="0x80" /&gt;
              &lt;enum name="clip_horizontal" value="0x08" /&gt;
              &lt;enum name="start" value="0x00800003" /&gt;
              &lt;enum name="end" value="0x00800005" /&gt;
          &lt;/attr&gt;
  
          &lt;attr name="icon_resource" format="integer"/&gt;
  
          &lt;attr name="icon_marginStart" format="dimension"/&gt;
          &lt;attr name="icon_marginEnd" format="dimension"/&gt;
          &lt;attr name="icon_marginTop" format="dimension"/&gt;
          &lt;attr name="icon_marginBottom" format="dimension"/&gt;
  
          &lt;attr name="text_source" format="string"/&gt;
  
          &lt;attr name="text_gravity" format="enum"&gt;
              &lt;enum name="top" value="0x30" /&gt;
              &lt;enum name="bottom" value="0x50" /&gt;
              &lt;enum name="left" value="0x03" /&gt;
              &lt;enum name="right" value="0x05" /&gt;
              &lt;enum name="center_vertical" value="0x10" /&gt;
              &lt;enum name="fill_vertical" value="0x70" /&gt;
              &lt;enum name="center_horizontal" value="0x01" /&gt;
              &lt;enum name="fill_horizontal" value="0x07" /&gt;
              &lt;enum name="center" value="0x11" /&gt;
              &lt;enum name="fill" value="0x77" /&gt;
              &lt;enum name="clip_vertical" value="0x80" /&gt;
              &lt;enum name="clip_horizontal" value="0x08" /&gt;
              &lt;enum name="start" value="0x00800003" /&gt;
              &lt;enum name="end" value="0x00800005" /&gt;
          &lt;/attr&gt;
  
          &lt;attr name="text_size" format="dimension"/&gt;
          &lt;attr name="text_font" format="string"/&gt;
          &lt;attr name="text_color" format="color"/&gt;
      &lt;/declare-styleable&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong><em>Implementation in RegisterActivity:</em></strong></p>
  
  <pre><code>&lt;com.android.neuron.custombuttons.FacebookCustomButton
                  android:layout_width="match_parent"
                  android:layout_height="40dp"
                  app:text_source="@string/facebook_signup_button_text"
                  app:text_size="14sp"
                  app:text_color="@color/white"
                  app:text_font="@font/roboto_medium"
                  app:text_gravity="center"
                  app:icon_resource="@drawable/ic_fb_white"
                  app:icon_gravity="center"
                  app:icon_height="24dp"
                  app:icon_width="24dp"
                  app:icon_marginBottom="0dp"
                  app:icon_marginEnd="42dp"
                  app:icon_marginStart="8dp"
                  app:icon_marginTop="0dp" /&gt;
  </code></pre>