參考:http://www.reibang.com/p/61b79e7f88fc
在使用
cn.finalteam.rxgalleryfinal
com.shehabic.droppy
發(fā)現(xiàn)樣式可在style中配置,
定義如下
/ * @param set The base set of attribute values. May be null.
* @param attrs The desired attributes to be retrieved.
* @param defStyleAttr An attribute in the current theme that contains a
* reference to a style resource that supplies
* defaults values for the TypedArray. Can be
* 0 to not look for defaults.
* @param defStyleRes A resource identifier of a style resource that
* supplies default values for the TypedArray,
* used only if defStyleAttr is 0 or can not be found
* in the theme. Can be 0 to not look for defaults.
* /
/ *
* @param attrs 要解析的那些屬性值
* @param set layout的布局配置的
* @param defStyleAttr 通過attr設(shè)置
* @param defStyleRes 默認(rèn)的一個樣式
* /
public final TypedArray obtainStyledAttributes(
AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
@StyleRes int defStyleRes) {
return getTheme().obtainStyledAttributes(
set, attrs, defStyleAttr, defStyleRes);
}
優(yōu)先級 set>defStyleAttr>defStyleRes
defStyleAttr示例
<attr name="xin_tv_attr" format="reference"></attr>
<style name="ActivityTheme" parent="Theme.AppCompat.Light">
<item name="xin_tv_attr">@style/xin_tv_style</item>
</style>
<style name="xin_tv_style">
<item name="xin_color">#ffff00</item>
<item name="xin_size">16sp</item>
</style>
TypedArray typedArray = obtainStyledAttributes(null,
R.styleable.xin_tv, R.attr.xin_tv_attr, R.style.xin_tv2);
1最易、資源文件定義
declare-styleable 與attr的區(qū)別
declare-styleable 相當(dāng)于attr的集合
2艳馒、發(fā)現(xiàn)defStyleAttr設(shè)置在layout布局文件中不起作用,設(shè)置在Activity的theme上或app Theme
3躯舔、TypedArray的使用
int color2 = typedArray.getColor(R.styleable.xin_tv_xin_color, Color.BLUE);
typedArray.recycle();