title: Can someone explain me declare-styleable XML tag in this example and the theory behind its use?
body: <p>I'm reading Beginning Android 4 Development and in chapter 5 it talks about <em>Gallery</em> and <em>ImageVievs</em> and introduces the <em>declare-styleable</em> XML tag without explaining its purpose.. I tried to find some info also on the reference, without luck.. For example we have the following:</p>
  
  <p><strong>res/values/attrs.xml</strong></p>
  
  
  
  <pre><code>&lt;?xml version=”1.0” encoding=”utf-8”?&gt; 
  &lt;resources&gt;
      &lt;declare-styleable name=”Gallery1”&gt;
          &lt;attr name=”android:galleryItemBackground” /&gt;
      &lt;/declare-styleable&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>example.java</strong></p>
  
  
  
  <pre><code>public class GalleryActivity extends Activity {
  [...]
      public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState);    
          setContentView(R.layout.main);
          Gallery gallery = (Gallery) findViewById(R.id.gallery1);
          gallery.setAdapter(new ImageAdapter(this)); 
          [...]
      }
  
      [...]
  
      public class ImageAdapter extends BaseAdapter {
          [...]
          int itemBackground;
  
          public ImageAdapter(Context c) {
              context = c;
              //---setting the style---
              TypedArray a = obtainStyledAttributes(
              R.styleable.Gallery1); 
              itemBackground = a.getResourceId(
                          R.styleable.Gallery1_android_galleryItemBackground, 0);
              a.recycle();
          }
  
          public View getView(int position, View convertView, ViewGroup parent) {
              ImageView imageView;
              [...]
              imageView.setBackgroundResource(itemBackground);
              return imageView; 
          }
      }
  }
  </code></pre>
  
  <p>I've read the code a few times and I don't really understand the purpose of defining this styleable <em>Gallery1</em> with a single <em>attr</em> child only with a <em>name</em> attribute.. can you help me? Is this <em>galleryItemBackground</em> something provided by the system or is it something defined by us? What are we doing in this piece of code?</p>
  
  <p>Thank you in advance for any help!</p>