當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。