当前位置: 首页>>代码示例>>Java>>正文


Java AttributeSet.getAttributeResourceValue方法代码示例

本文整理汇总了Java中android.util.AttributeSet.getAttributeResourceValue方法的典型用法代码示例。如果您正苦于以下问题:Java AttributeSet.getAttributeResourceValue方法的具体用法?Java AttributeSet.getAttributeResourceValue怎么用?Java AttributeSet.getAttributeResourceValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.util.AttributeSet的用法示例。


在下文中一共展示了AttributeSet.getAttributeResourceValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pullFontPathFromView

import android.util.AttributeSet; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:CalligraphyUtils.java

示例2: pullFontPathFromView

import android.util.AttributeSet; //导入方法依赖的package包/类
/**
 * 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
 */
@FontRes
static int pullFontPathFromView(Context context, AttributeSet attrs, int[] attributeId) {
    if (attributeId == null || attrs == null)
        return 0;

    final String attributeName;
    try {
        attributeName = context.getResources().getResourceEntryName(attributeId[0]);
    } catch (Resources.NotFoundException e) {
        // invalid attribute ID
        return 0;
    }

    final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1);
    return stringResourceId > 0
            ? stringResourceId
            : attrs.getAttributeIntValue(null, attributeName, 0);
}
 
开发者ID:takahirom,项目名称:DownloadableCalligraphy,代码行数:27,代码来源:CalligraphyUtils.java

示例3: getResourceId

import android.util.AttributeSet; //导入方法依赖的package包/类
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 ("drawable".equals(resourceTypeName)
				|| "raw".equals(resourceTypeName)) {
			if (!setResource(view, isSrc, resId)) {
				return resId;
			}
		}
	}
	return 0;
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:17,代码来源:GifViewUtils.java

示例4: initFields

import android.util.AttributeSet; //导入方法依赖的package包/类
private void initFields(Context context, AttributeSet attrs) {
    int maxValueResourceId = attrs.getAttributeResourceValue(ANDROID_NS, "max", R.integer.pref_default_int_value);
    maxSeekBarValue = context.getResources().getInteger(maxValueResourceId);

    int minValueResourceId = attrs.getAttributeResourceValue(SEEKBAR_NS, "min", R.integer.pref_default_int_value);
    minSeekBarValue = context.getResources().getInteger(minValueResourceId);

    int stepSizeValueResourceId = attrs.getAttributeResourceValue(SEEKBAR_NS, "stepSize", R.integer.pref_default_int_value);
    seekBarStepSize = context.getResources().getInteger(stepSizeValueResourceId);

    Log.v("Attribute", "max = " + maxSeekBarValue);
    Log.v("Attribute", "min = " + minSeekBarValue);
    Log.v("Attribute", "step = " + seekBarStepSize);
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:15,代码来源:SeekBarPreference.java

示例5: setRippleAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
protected void setRippleAttributes(AttributeSet attrs) {
	/**
	 * 初始化按压时涟漪的颜色
	 * Set Ripple Color
	 * Color by resource
	 */
	int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1);
	if(color != -1){
		rippleColor = getResources().getColor(color);
		settedRippleColor = true;
	}else{
		// Color by hexadecimal
		int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16进制的颜色
		if(rColor != -1 && !isInEditMode()) {
			rippleColor = rColor;
			settedRippleColor = true;
		}
	}
	
	/**
	 * 初始化涟漪扩展的速度 
	 * init Ripple speed
	 */
	rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
	
	/**
	 * 设定涟漪的响应时间
	 */
	clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:31,代码来源:RippleView.java

示例6: onInitAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
protected void onInitAttributes(AttributeSet attrs) {
	super.onInitAttributes(attrs);
	// 设置按钮中的图标
	int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1);
	if (iconResource != -1) {
		iconDrawable = getResources().getDrawable(iconResource);
	}

	// animation
	boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "animate", false);
	if (animate) {
		playAnimation();
	}
	
	if (iconDrawable != null) {
		icon.setBackgroundDrawable(iconDrawable);
	}
	// 设置按钮中图标的大小
	String size = attrs.getAttributeValue(MATERIALDESIGNXML, "iconSize");
	if (size != null) {
		iconSize = (int) Utils.dipOrDpToFloat(size);
	}
	setIconParams();
	addView(icon);
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:28,代码来源:ButtonFloat.java

示例7: setBackgroundAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
/**
 * 设置背景色
 * Set background Color
 */
protected void setBackgroundAttributes(AttributeSet attrs) {
	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 && !isInEditMode()) {
			setBackgroundColor(background);
		}else {
			setBackgroundColor(backgroundColor);// 如果没有设置,就用这个颜色
		}
	}
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:19,代码来源:CustomView.java

示例8: setAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(dpToPx(48, getResources()));
        setMinimumWidth(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);
        }

        min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
        max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0);
        value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min);

        ball = new Ball(getContext());
        LayoutParams params = new LayoutParams(dpToPx(15, getResources()), dpToPx(15, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

    }
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:32,代码来源:Slider.java

示例9: getAttributeValue

import android.util.AttributeSet; //导入方法依赖的package包/类
public String getAttributeValue(AttributeSet attr, String attrName, String defaultValue) {
	String value;
	int resId = attr.getAttributeResourceValue(null, attrName, -1);
	
    if (resId < 0) {
    	value = attr.getAttributeValue(null, attrName);
    }
    else {
    	value = getContext().getResources().getString(resId);
    }
    
    return (value != null ? value : defaultValue);
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:14,代码来源:CustomizableGraphView.java

示例10: setAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
@Override
protected void setAttributes(AttributeSet attrs) {
	// Set text button
	String text = null;
	int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1);
	if(textResource != -1){
		text = getResources().getString(textResource);
	}else{
		text = attrs.getAttributeValue(ANDROIDXML,"text");
	}
	if(text != null){
		textButton = new TextView(getContext());
		textButton.setText(text.toUpperCase());
		textButton.setTextColor(backgroundColor);
		textButton.setTypeface(null, Typeface.BOLD);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		textButton.setLayoutParams(params);
		addView(textButton);
	}
	int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
	if(bacgroundColor != -1){
		setBackgroundColor(getResources().getColor(bacgroundColor));
	}else{
		// Color by hexadecimal
		// Color by hexadecimal
		background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
		if (background != -1)
			setBackgroundColor(background);
	}
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:32,代码来源:ButtonFlat.java

示例11: getAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
/**
 * 解析 xml 文件
 *
 * @param attrs
 */
public void getAttributes(@Nullable AttributeSet attrs) {
    String namespace = "http://schemas.android.com/apk/res-auto";
    int switchBackground = attrs.getAttributeResourceValue(namespace, "switch_background", -1);
    setBackgroundSwitchResource(switchBackground);
    int slideButton = attrs.getAttributeResourceValue(namespace, "slide_button", -1);
    setSlideButtonResource(slideButton);
    boolean switchState = attrs.getAttributeBooleanValue(namespace, "switch_state", false);
    setSwitchState(switchState);
}
 
开发者ID:sleticalboy,项目名称:CustomWeight,代码行数:15,代码来源:CustomToggleView.java

示例12: onInitAttributes

import android.util.AttributeSet; //导入方法依赖的package包/类
@Override
protected void onInitAttributes(AttributeSet attrs) {
	super.onInitAttributes(attrs);
	if (isInEditMode()) {
		// 为了在编译器中预览时不报空指针,在这里产生一个textView对象。实际中不会产生的。
		textButton = new TextView(getContext());
	}
	String text = null;
	/**
	 * 设置按钮上的文字内容
	 */
	int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1);
	if(textResource != -1){
		text = getResources().getString(textResource);
	}else{
		//如果没有文字资源,也就是@String/xx,那么就设置文字
		text = attrs.getAttributeValue(ANDROIDXML,"text");
	}
	
	/**
	 * 当文字不为空的时候,TextView设置文字,否则不设置文字
	 */
	if(text != null){
		textButton.setText(text);
	}
	
	/**
	 * 设置textSize
	 */
	String textSize = attrs.getAttributeValue(ANDROIDXML,"textSize");
	if (text != null && textSize != null) {
		textSize = textSize.substring(0, textSize.length() - 2);//12sp->12
		textButton.setTextSize(Float.parseFloat(textSize));
	}
	
	/**
	 * 设置textColor
	 */
	int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1);
	if(text != null && textColor != -1){
		textButton.setTextColor(getResources().getColor(textColor));
	}
	else if(text != null ){
		// 16进制的color
		String color = attrs.getAttributeValue(ANDROIDXML,"textColor");
		if(color != null && !isInEditMode()) {
			textButton.setTextColor(Color.parseColor(color));
		}else {
			textButton.setTextColor(defaultTextColor);
		}
	}
	textButton.setTypeface(null, Typeface.BOLD);
	//textButton.setPadding(5, 5, 5, 5);
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()));
	textButton.setLayoutParams(params);
	addView(textButton);
	
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:62,代码来源:ButtonRectangle.java


注:本文中的android.util.AttributeSet.getAttributeResourceValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。