drawable文件:selector开头,当被点击,则属性发生变化,将要使用的控件:Android:background=“@drawable/…”进行引用
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/list1"/>
<item android:drawable="@color/listview_default"/>
</selector>
attr属性文件,给某些控件增加属性:在res\values文件下创建attrs.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="textview">
<attr name="textColor" format="color"/>
<attr name="textsize" format="dimension"/>
</declare-styleable>
</resources>
在代码中获取attr文件中设定的属性,然后为控件设置相应的属性。
TypedArray attraray= getContext().obtainStyledAttributes(attrs, R.styled.textview)
textColor=attraray.getColor(R.styled.textview_textColor , textColor);//参数二为初始化过的颜色值。将此属性赋值为此。
使用完之后记得回收资源:attrarray.recycle();
引用时需要增加命名空间xlns:app=" "
app:textColor= " ”;
Bitmap:getWidth()与getHeight()和获取其长宽
Drawable:getIntrinsicWidth()、getIntrinsicHeight()