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

0

I want to apply a template (Theme) created by me, and the error is when I relate a textview with an attribute pointer 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 attr.xml file is created in the res / values folder

<?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!

    
asked by Axel Stermann 10.11.2016 в 14:35
source

1 answer

2

To define a reference attribute you must 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"
 ..... />

EDITING

Well, as you know the attributes with format="reference" are as their name says "refer" to different types of <style> or layouts already defined, in the question that you leave the user says that you believe the attr (as I leave it to you). Then in the file define <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 define

 <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 <style> Theme.Small there is an item which is called textTitle (which is the attr you created) and gives @style/small_title_text which is the reference as it is created in attr.xml

The error you have is that you created the attr but not the reference to which you 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"
 />
    
answered by 10.11.2016 / 15:08
source