Note that there are some explanatory texts on larger screens.

plurals
  1. POIs such trick with CustomView safe?
    primarykey
    data
    text
    <p>Currently i start working on support of one project, and there i found one very intresting trick. It give an oportunity do not write full class name for CustomView in xml and it look's pretty dirty i think. </p> <p>Here are steps for this trick implementation:</p> <p>1) Create our own <code>android.view</code> package in our project.</p> <p>2) Create <code>CustomTextView extends TextView</code> and put it in <code>android.view</code> package.</p> <p>3) Use it in XML like any other Android <code>view</code></p> <pre><code> &lt;CustomTextView android:angle="90" android:endColor="#efa600" android:paddingLeft="0dp" android:startColor="#ffe396" android:text="" android:textSize="24dp" android:textStyle="bold" /&gt; </code></pre> <p>4) Use standard Android attributes instead of custom :</p> <pre><code>public CustomTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); int[] ids = new int[attrs.getAttributeCount()]; for (int i = 0; i &lt; attrs.getAttributeCount(); i++) { ids[i] = attrs.getAttributeNameResource(i); } TypedArray a = context.obtainStyledAttributes(attrs, ids, defStyle, 0); for (int i = 0; i &lt; attrs.getAttributeCount(); i++) { String attrName = attrs.getAttributeName(i); if (attrName == null) continue; if (attrName.equals("startColor")) { mStartColor = a.getColor(i, -1); } else if (attrName.equals("endColor")) { mEndColor = a.getColor(i, -1); } else if (attrName.equals("angle")) { mAngle = a.getFloat(i, 0); } } a.recycle(); } </code></pre> <p>Does such way is safe or maybe it can cause any problems?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload