title: How to Use View.isInEditMode() in custom views to skip code?
body: <p>I'm using a custom view to show gradient color filled TextView as bellow: </p>
  
  <pre><code>public class GradientTextView extends TextView {
  public GradientTextView(Context context) {
      super(context, null, -1);
  }
  
  public GradientTextView(Context context,
                          AttributeSet attrs) {
      super(context, attrs, -1);
  }
  
  public GradientTextView(Context context,
                          AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  
      if (!isInEditMode()) {
          GradientTextView.getTextColor(context, null, defStyle);
      }
  }
  
  @Override
  protected void onLayout(boolean changed,
                          int left, int top, int right, int bottom) {
      super.onLayout(changed, left, top, right, bottom);
      if (changed) {
          getPaint().setShader(new LinearGradient(
                  0, 0, 0, getHeight(),
                  Color.parseColor(Color.WHITE), Color.parseColor(Color.BLACK),
                  Shader.TileMode.CLAMP));
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It works finely on device or emulator but I get Rendering Problem in xml previewer of Android studio which suggests using  View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE and shows this error stack:</p>
  
  <pre><code>java.lang.NullPointerException
  </code></pre>
  
  <p>Can anyone please help me over this?</p>