Note that there are some explanatory texts on larger screens.

plurals
  1. POStyleable attribute not passed to class
    primarykey
    data
    text
    <p>Hi i'm trying to pass an attribute from theme to code but it is not working.</p> <p>here is my code</p> <p>styles.xml</p> <pre><code>&lt;style name="Theme.custom"&gt; &lt;item name="skin"&gt;custom&lt;/item&gt; &lt;/style&gt; </code></pre> <p>manifest:</p> <pre><code>&lt;application android:theme="@style/Theme.custom" &gt; ... &lt;/application&gt; </code></pre> <p>attrs:</p> <pre><code>&lt;attr name="skin" format="reference|string" /&gt; &lt;declare-styleable name="SkinImageView"&gt; &lt;attr name="skin" /&gt; &lt;attr name="resource" /&gt; &lt;/declare-styleable&gt; &lt;declare-styleable name="SkinButton"&gt; &lt;attr name="skin" /&gt; &lt;attr name="resource" /&gt; &lt;attr name="type" format="reference|string"&gt;&lt;/attr&gt; &lt;attr name="skinButtonStyle" format="reference" /&gt; &lt;attr name="imageButton" format="boolean" /&gt; &lt;attr name="android:enabled" /&gt; &lt;attr name="android:clickable" /&gt; &lt;/declare-styleable&gt; </code></pre> <p>SkinImageView.java</p> <pre><code>public class SkinImageView extends ImageView { protected String skin; public SkinImageView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SkinImageView); String name = array.getString(R.styleable.SkinImageView_resource); String sskin = array.getString(R.styleable.SkinImageView_skin); array.recycle(); // skin = "NEW:" } } </code></pre> <p>The same code is in SkinButton.java</p> <pre><code>public class SkinButton extends Button { private String skin; public SkinButton(Context context) { this(context, null); } public SkinButton(Context context, AttributeSet attrs) { this(context, attrs, R.attr.skinButtonStyle); } public SkinButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SkinButton, defStyle, R.style.SkinButtonDefault); setEnabled(array.getBoolean(R.styleable.SkinButton_android_enabled, true)); setClickable(array.getBoolean(R.styleable.SkinButton_android_clickable, true)); String name = array.getString(R.styleable.SkinButton_resource); String type = array.getString(R.styleable.SkinButton_type); skin = array.getString(R.styleable.SkinButton_skin); array.recycle(); // skin = "custom" } } </code></pre> <p>BUT!!!!</p> <p>Skin button resolves skin as "custom" SkinImageView resolves skin as "NEW:". I've searched there is no "NEW" in entire project</p> <p>any help?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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