Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - use attributes to tweak custom styles
    text
    copied!<p>here's my issue. I have defined custom themes and styles, so as to customize various Views, in the relevant .xml files. Here are some code extracts:</p> <p>themes.xml:</p> <pre><code>... &lt;style name="Legacy" parent="android:Theme.NoTitleBar"&gt; &lt;item name="android:buttonStyle"&gt;@style/Legacy.Button&lt;/item&gt; ... &lt;/style&gt; </code></pre> <p>styles.xml:</p> <pre><code>... &lt;style name="Legacy.Button" parent="@android:style/Widget.Button"&gt; &lt;item name="android:textColor"&gt;#ffffff&lt;/item&gt; &lt;item name="android:background"&gt;@drawable/button_selector_blue&lt;/item&gt; &lt;item name="android:textSize"&gt;15dp&lt;/item&gt; &lt;/style&gt; </code></pre> <p>Let's say I set my application's theme to Legacy. If I use a Button in a layout, it will get my custom default parameters (white text, background is @drawable/button_selector_blue, etc).</p> <p>Now let's say I want to keep those parameters save for the text size: I'd like to have some buttons with a larger text size, which would be defined in an titleSize attribute in attrs.xml:</p> <pre><code>... &lt;attr name="titleSize" format="reference|dimension" /&gt; </code></pre> <p>and which value is set for each theme in my themes.xml file.</p> <p>So my layout would contain something like:</p> <pre><code>&lt;Button android:id="@+idmyButtonId" android:drawableRight="@drawable/aDrawable" android:text="@string/someText" android:textSize="?titleSize" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/Button&gt; </code></pre> <p>When launching my app I get the following error: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2</p> <p>So it seems I cannot tweak custom styles using attributes - at least not this way. Is such a thing possible ? If not, what would you use to achieve such a result ?</p> <p>I'd like to give the user the ability to select among different themes, so I can't just define an additionnal ButtonWithLargeText style and directly use it in my layout.</p> <p>Thanks for your help !</p>
 

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