android.util.AttributeSet#getStyleAttribute ( )源码实例Demo

下面列出了android.util.AttributeSet#getStyleAttribute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AssistantBySDK   文件: LoginoutButton.java
/**
 * 加载默认的样式(蓝色)。
 * 
 * @param attrs XML 属性集合对象
 */
private void loadDefaultStyle(AttributeSet attrs) {
	if (attrs != null && 0 == attrs.getStyleAttribute()) {
		Resources res = getResources();
		this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
		this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
		this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
		this.setCompoundDrawablePadding(
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
        		res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
	}
}
 
源代码2 项目: Simpler   文件: LoginoutButton.java
/**
 * 加载默认的样式(蓝色)。
 * 
 * @param attrs XML 属性集合对象
 */
private void loadDefaultStyle(AttributeSet attrs) {
	if (attrs != null && 0 == attrs.getStyleAttribute()) {
		Resources res = getResources();
		this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
		this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
		this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
		this.setCompoundDrawablePadding(
				res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
        		res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
	}
}
 
源代码3 项目: Genius-Android   文件: Ui.java
/**
 * Get Background color if the attr is color value
 *
 * @param context Context
 * @param attrs   AttributeSet
 * @return Color
 */
public static int getBackgroundColor(Context context, AttributeSet attrs) {
    int color = Color.TRANSPARENT;

    if (isHaveAttribute(attrs, "background")) {
        int styleId = attrs.getStyleAttribute();
        int[] attributesArray = new int[]{android.R.attr.background};

        try {
            TypedArray typedArray = context.obtainStyledAttributes(styleId, attributesArray);
            if (typedArray.length() > 0)
                color = typedArray.getColor(0, color);
            typedArray.recycle();
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        }
    }

    return color;
}
 
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
        this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
        this.setGravity(Gravity.CENTER);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码5 项目: leanback-extensions   文件: IconCardView.java
private static int getIconCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.IconCardView);
		style = styledAttrs.getResourceId(R.styleable.IconCardView_icon_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
源代码6 项目: leanback-extensions   文件: LoadingCardView.java
private static int getLoadingCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.LoadingCardView);
		style = styledAttrs.getResourceId(R.styleable.LoadingCardView_loading_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
源代码7 项目: leanback-extensions   文件: ProcessCardView.java
private static int getIconCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
	int style = attrs == null ? 0 : attrs.getStyleAttribute();

	if (style == 0) {
		TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.ProcessCardView);
		style = styledAttrs.getResourceId(R.styleable.ProcessCardView_process_theme, 0);
		styledAttrs.recycle();
	}

	return style;
}
 
private TypedArray getTypedArray(@XmlRes int xmlId) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, xmlId, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Badge;
  }
  return context
      .getTheme()
      .obtainStyledAttributes(attrs, R.styleable.Badge, R.attr.badgeStyle, style);
}
 
源代码9 项目: facebook-api-android-maven   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码10 项目: platform-friends-android   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码11 项目: Klyph   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码12 项目: barterli_android   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码13 项目: android-skeleton-project   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码14 项目: FacebookImageShareIntent   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
        this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
        this.setGravity(Gravity.CENTER);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码16 项目: Abelana-Android   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码17 项目: KlyphMessenger   文件: LoginButton.java
/**
 * Create the LoginButton by inflating from XML
 *
 * @see View#View(Context, AttributeSet)
 */
public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        // apparently there's no method of setting a default style in xml,
        // so in case the users do not explicitly specify a style, we need
        // to use sensible defaults.
        this.setGravity(Gravity.CENTER);
        this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        if (isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in with Facebook";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_button_blue);
            this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_inverse_icon, 0, 0, 0);
            this.setCompoundDrawablePadding(
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_compound_drawable_padding));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
        }
    }
    parseAttributes(attrs);
    if (!isInEditMode()) {
        initializeActiveSessionWithCachedToken(context);
    }        
}
 
源代码18 项目: GreenDamFileExploere   文件: FlatTextView.java
private void init(AttributeSet attrs) {

        if (attributes == null)
            attributes = new Attributes(this, getResources());

        if (attrs != null) {

            // getting android default tags for textColor and textColorHint
            String textColorAttribute = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColor");
            int styleId = attrs.getStyleAttribute();
            int[] attributesArray = new int[] { android.R.attr.textColor };
            TypedArray styleTextColorTypedArray = getContext().obtainStyledAttributes(styleId, attributesArray);
            // color might have values from the entire integer range, so to find
            // out if there is any color set,
            // checking if default value is returned is not enough. Thus we get
            // color with two different
            // default values - if returned value is the same, it means color is
            // set
            int styleTextColor1 = styleTextColorTypedArray.getColor(0, -1);
            int styleTextColor2 = styleTextColorTypedArray.getColor(0, 1);
            hasOwnTextColor = textColorAttribute != null || styleTextColor1 == styleTextColor2;
            styleTextColorTypedArray.recycle();

            TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatTextView);

            // getting common attributes
            int customTheme = a.getResourceId(R.styleable.fl_FlatTextView_fl_theme, Attributes.DEFAULT_THEME);
            attributes.setThemeSilent(customTheme, getResources());

            attributes.setFontFamily(a.getString(R.styleable.fl_FlatTextView_fl_fontFamily));
            attributes.setFontWeight(a.getString(R.styleable.fl_FlatTextView_fl_fontWeight));
            attributes.setFontExtension(a.getString(R.styleable.fl_FlatTextView_fl_fontExtension));

            attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatTextView_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
            attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatTextView_fl_borderWidth, 0));

            // getting view specific attributes
            textColor = a.getInt(R.styleable.fl_FlatTextView_fl_textColor, textColor);
            backgroundColor = a.getInt(R.styleable.fl_FlatTextView_fl_backgroundColor, backgroundColor);
            customBackgroundColor = a.getInt(R.styleable.fl_FlatTextView_fl_customBackgroundColor, customBackgroundColor);

            a.recycle();
        }

        GradientDrawable gradientDrawable = new GradientDrawable();
        if (backgroundColor != Attributes.INVALID) {
            gradientDrawable.setColor(attributes.getColor(backgroundColor));
        } else if (customBackgroundColor != Attributes.INVALID) {
            gradientDrawable.setColor(customBackgroundColor);
        } else {
            gradientDrawable.setColor(Color.TRANSPARENT);
        }
        gradientDrawable.setCornerRadius(attributes.getRadius());
        gradientDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(textColor));
        setBackgroundDrawable(gradientDrawable);

        // setting the text color only if there is no android:textColor
        // attribute used
        if (!hasOwnTextColor)
            setTextColor(attributes.getColor(textColor));

        // check for IDE preview render
        if (!this.isInEditMode()) {
            Typeface typeface = FlatUI.getFont(getContext(), attributes);
            if (typeface != null)
                setTypeface(typeface);
        }
    }
 
/**
 * Returns a BadgeDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Badge} and a custom <code>style</code> attribute are supported. A badge resource
 * may look like:
 *
 * <pre>{@code
 * <badge
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Badge"
 *     app:maxCharacterCount="2"/>
 * }</pre>
 */
@NonNull
public static BadgeDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = DEFAULT_STYLE;
  }
  return createFromAttributes(context, attrs, DEFAULT_THEME_ATTR, style);
}
 
源代码20 项目: material-components-android   文件: ChipDrawable.java
/**
 * Returns a ChipDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Chip} and a custom <code>style</code> attribute are supported. A chip resource may
 * look like:
 *
 * <pre>{@code
 * <chip
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Chip.Entry"
 *     app:chipIcon="@drawable/custom_icon"/>
 * }</pre>
 */
@NonNull
public static ChipDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "chip");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Chip_Entry;
  }
  return createFromAttributes(context, attrs, R.attr.chipStandaloneStyle, style);
}