0 votes

Error: No resource found that matches the given name (at 'style' with value '?android:attr

I want to apply a template (Theme) created by me, and the error is when I relate a textview with a pointer attribute that is used in the Theme

<TextView
        android:id="@+id/textView1"
        style="?android:attr/textTitle"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="HOY QUIERO DARLE DE BEBER AL SEDIENTO"/>

The file attr.xml this is created in the folder res/values

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <!-- View styles -->
   <attr name="textTitle" format="reference" />
   <attr name="textSubtitle" format="reference" />
   <attr name="textBody" format="reference" />
</resources>

Thanks in advance!

2voto

sioesi Points 9832

To define a reference attribute you declare

<declare-styleable name="Title">
    <attr name="textTitle" format="reference" />
    <attr name="textSubtitle" format="reference" />
    <attr name="textBody" format="reference" />
</declare-styleable>

And to create your TextView

<com.tuapp.Title
 android:id="@+id/title"
 custom:textTitle="@color/my_color1"
 custom:textSubtitle="@color/my_color2"
 custom:textBody = "@color/my_color3"
 ..... />

EDITION

Well, as you know the attributes with format="reference" are as what the name says "refer" to different types of <style> or layouts already defined, in the question that you let the user say that you think the attr (such as you leave it to me). Then in the file defines <style>

style.xml

<style name="small_title_text">
  <item name="android:textSize">22sp</item>
  <item name="android:textColor">@color/green</item>
  <item name="android:textStyle">normal</item>
  <item name="android:paddingBottom">5dip</item>
</style>

And then in this same file defines

 <style name="Theme.Small">
    <item name="textTitle">@style/small_title_text</item>
    <item name="textBody">@style/small_body_text</item>
 </style>

Where it says that for the <style> Theme.Small there is an item called textTitle (that is the attr that you created) and gives you @style/small_title_text , which is the reference as this is created in attr.xml

The error that you have is that you created the attr but not the reference to which it will obey.

<TextView  
  android:id="@+id/title" 
  style="?textTitle"  //<---- Hace referencia al Item y no al attr como piensas 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="Select the size of the text"
 />

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X