本文整理了Java中android.util.AttributeSet.getAttributeResourceValue()
方法的一些代码示例,展示了AttributeSet.getAttributeResourceValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AttributeSet.getAttributeResourceValue()
方法的具体详情如下:
包路径:android.util.AttributeSet
类名称:AttributeSet
方法名:getAttributeResourceValue
暂无
代码示例来源:origin: robolectric/robolectric
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context, R.layout.inner_merge, this);
attributeResourceValue = attrs.getAttributeResourceValue(ROBOLECTRIC_RES_URI, "message", -1);
namespacedResourceValue = attrs.getAttributeResourceValue(FAKE_URI, "message", -1);
}
}
代码示例来源:origin: chrisjenx/Calligraphy
/**
* Tries to pull the Custom Attribute directly from the TextView.
*
* @param context Activity Context
* @param attrs View Attributes
* @param attributeId if -1 returns null.
* @return null if attribute is not defined or added to View
*/
static String pullFontPathFromView(Context context, AttributeSet attrs, int[] attributeId) {
if (attributeId == null || attrs == null)
return null;
final String attributeName;
try {
attributeName = context.getResources().getResourceEntryName(attributeId[0]);
} catch (Resources.NotFoundException e) {
// invalid attribute ID
return null;
}
final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
return stringResourceId > 0
? context.getString(stringResourceId)
: attrs.getAttributeValue(null, attributeName);
}
代码示例来源:origin: koral--/android-gif-drawable
private static int getResourceId(ImageView view, AttributeSet attrs, final boolean isSrc) {
final int resId = attrs.getAttributeResourceValue(ANDROID_NS, isSrc ? "src" : "background", 0);
if (resId > 0) {
final String resourceTypeName = view.getResources().getResourceTypeName(resId);
if (SUPPORTED_RESOURCE_TYPE_NAMES.contains(resourceTypeName) && !setResource(view, isSrc, resId)) {
return resId;
}
}
return 0;
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1);
if(textResource != -1){
text = getResources().getString(textResource);
addView(textButton);
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
setBackgroundColor(getResources().getColor(bacgroundColor));
代码示例来源:origin: koral--/android-gif-drawable
private void init(AttributeSet attrs, int defStyle, int defStyleRes) {
if (attrs != null) {
Drawable left = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableLeft", 0));
Drawable top = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableTop", 0));
Drawable right = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableRight", 0));
Drawable bottom = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableBottom", 0));
Drawable start = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableStart", 0));
Drawable end = getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "drawableEnd", 0));
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
if (start == null) {
start = left;
}
if (end == null) {
end = right;
}
} else {
if (start == null) {
start = right;
}
if (end == null) {
end = left;
}
}
setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
setBackground(getGifOrDefaultDrawable(attrs.getAttributeResourceValue(GifViewUtils.ANDROID_NS, "background", 0)));
viewAttributes = new GifViewUtils.GifViewAttributes(this, attrs, defStyle, defStyleRes);
applyGifViewAttributes();
}
viewAttributes = new GifViewUtils.GifViewAttributes();
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
protected void setAttributes(AttributeSet attrs){
setBackgroundResource(R.drawable.background_button_rectangle);
//Set background Color
// Color by resource
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
setBackgroundColor(getResources().getColor(bacgroundColor));
}else{
// Color by hexadecimal
String background = attrs.getAttributeValue(ANDROIDXML,"background");
if(background != null)
setBackgroundColor(Color.parseColor(background));
else
setBackgroundColor(this.backgroundColor);
}
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
protected void setAttributes(AttributeSet attrs){
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
setBackgroundColor(getResources().getColor(bacgroundColor));
int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML,
"rippleColor", -1);
if (rippleColor != -1) {
int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1);
if(iconResource != -1)
drawableIcon = getResources().getDrawable(iconResource);
代码示例来源:origin: navasmdc/MaterialDesignLibrary
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
setBackgroundColor(getResources().getColor(bacgroundColor));
代码示例来源:origin: navasmdc/MaterialDesignLibrary
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
"background", -1);
if (bacgroundColor != -1) {
int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML,
"rippleColor", -1);
if (rippleColor != -1) {
代码示例来源:origin: robolectric/robolectric
@Test
public void getAttributeResourceValue_shouldReturnDefaultValueWhenNotInAttributeSet() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(APP_NS, "message", -1))
.isEqualTo(-1);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAttributeResourceValue_withNamespace_shouldReturnTheResourceValue() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(R.attr.message, "@string/howdy")
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(APP_NS, "message", 0))
.isEqualTo(R.string.howdy);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getSystemAttributeResourceValue_shouldReturnDefaultValueForNullResourceId() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.text, AttributeResource.NULL_VALUE)
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(ANDROID_RES_NS_PREFIX + "com.some.namespace", "text", 0))
.isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAttributeResourceValueWithLeadingWhitespace_shouldReturnTheResourceValue() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.text, " @android:string/ok")
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(ANDROID_NS, "text", 0))
.isEqualTo(android.R.string.ok);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getSystemAttributeResourceValue_shouldReturnDefaultValueForNonMatchingNamespaceId() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.id, "@+id/text1")
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(ANDROID_RES_NS_PREFIX + "com.some.other.namespace", "id", 0))
.isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAttributeResourceValue_shouldReturnTheResourceValue() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.text, "@android:string/ok")
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(ANDROID_NS, "text", 0))
.isEqualTo(android.R.string.ok);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldCopeWithDefiningLocalIds() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.id, "@+id/text1")
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(ANDROID_NS, "id", 0))
.isEqualTo(R.id.text1);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAttributeResourceValue_shouldReturnDefaultValueWhenAttributeIsNull() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
.addAttribute(android.R.attr.text, AttributeResource.NULL_VALUE)
.build();
assertThat(roboAttributeSet.getAttributeResourceValue(APP_NS, "message", -1))
.isEqualTo(-1);
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
protected void setAttributes(AttributeSet attrs){
setMinimumHeight(Utils.dpToPx(32, getResources()));
setMinimumWidth(Utils.dpToPx(32, getResources()));
//Set background Color
// Color by resource
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
setBackgroundColor(getResources().getColor(bacgroundColor));
}else{
// Color by hexadecimal
int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
if (background != -1)
setBackgroundColor(background);
else
setBackgroundColor(Color.parseColor("#1E88E5"));
}
setMinimumHeight(Utils.dpToPx(3, getResources()));
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
protected void setAttributes(AttributeSet attrs) {
setBackgroundResource(R.drawable.background_transparent);
// Set size of view
setMinimumHeight(Utils.dpToPx(48, getResources()));
setMinimumWidth(Utils.dpToPx(80, getResources()));
// Set background Color
// Color by resource
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
"background", -1);
if (bacgroundColor != -1) {
setBackgroundColor(getResources().getColor(bacgroundColor));
} else {
// Color by hexadecimal
int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
if (background != -1)
setBackgroundColor(background);
}
check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check",
false);
eventCheck = check;
ball = new Ball(getContext());
RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
getResources()), Utils.dpToPx(20, getResources()));
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
ball.setLayoutParams(params);
addView(ball);
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
"background", -1);
if (bacgroundColor != -1) {
内容来源于网络,如有侵权,请联系作者删除!