---
title: "android attr.xml 怎么在主工程中设置library项目中背景或者其他一些属性。"
author: "liangoogle"
date: "2013-04-16T19:38:26Z"
tags: []
categories: ["移动开发"]
slug: "android-attr-xml-library"
draft: false
lastmod: "2013-04-16T19:38:38Z"
id: 1848464
url: "https://liangoogle.iteye.com/blog/1848464"
---

**怎么在主工程中设置library项目中背景或者其他一些属性值。**

attr.xml ：自定义属性。

format值参考：    [http://huangbo-2020.iteye.com/blog/1477611](http://huangbo-2020.iteye.com/blog/1477611)

1、自定义属性：

&lt;resources&gt;

&lt;attr name="searchViewCloseIcon" format="reference" /&gt;

&lt;/resources&gt;

            &lt;ImageView  
                android:layout\_width="wrap\_content"  
                android:layout\_height="match\_parent"  
                android:src="?attr/searchViewCloseIcon" /&gt;

在theme.xml中：

把这个值设在theme.xml的style中，这样aplication引用这个style时，就会对这个属性赋值。

 &lt;item name="searchViewCloseIcon"&gt;@drawable/abs\_\_ic\_clear&lt;/item&gt;

 在主工程中继承这个style，重新给searchViewCloseIcon赋值。