android.util.AttributeSet类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(89)

本文整理了Java中android.util.AttributeSet类的一些代码示例,展示了AttributeSet类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AttributeSet类的具体详情如下:
包路径:android.util.AttributeSet
类名称:AttributeSet

AttributeSet介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
public void attrsToTypedArray_shouldAllowMockedAttributeSets() throws Exception {
 if (!useLegacy()) return;
 AttributeSet mockAttributeSet = mock(AttributeSet.class);
 when(mockAttributeSet.getAttributeCount()).thenReturn(1);
 when(mockAttributeSet.getAttributeNameResource(0)).thenReturn(android.R.attr.windowBackground);
 when(mockAttributeSet.getAttributeName(0)).thenReturn("android:windowBackground");
 when(mockAttributeSet.getAttributeValue(0)).thenReturn("value");
 resources.obtainAttributes(mockAttributeSet, new int[]{android.R.attr.windowBackground});
}

代码示例来源: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: aa112901/remusic

protected static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
      final int stateResId = attrs.getAttributeNameResource(i);
      switch (stateResId) {
        case 0:
          break;
        case android.R.attr.color:
        case android.R.attr.alpha:
          // Ignore attributes from StateListDrawableItem and
          // AnimatedStateListDrawableItem.
          continue;
        default:
          states[j++] = attrs.getAttributeBooleanValue(i, false)
              ? stateResId : -stateResId;
      }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public SeekBarPreference(Context context, AttributeSet attrs) {
  super(context, attrs);
  mContext = context;
  mSuffix = attrs.getAttributeValue(androidns, "text");
  mDefault = attrs.getAttributeIntValue(androidns, "defaultValue", 0);
  mMax = attrs.getAttributeIntValue(androidns, "max", 100);
  mMin = attrs.getAttributeIntValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "min", 0);
  mInterval = attrs.getAttributeIntValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "interval", 1);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

for (int i = 0; i < attrs.getAttributeCount(); i++) {
  if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND)) {
    mBackGroundViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));
  if (attrs.getAttributeName(i).equals(ATTR_TEXTCOLOR)) {
    mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
  if (attrs.getAttributeName(i).equals(ATTR_TWO_TEXTCOLOR)) {
    mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
  if (attrs.getAttributeName(i).equals(ATTR_THREE_TEXTCOLOR)) {
    mOneTextColorViews.add(new AttrEntity<TextView>((TextView)view,getAttr(mClass,attrs.getAttributeValue(i))));
  if (attrs.getAttributeName(i).equals(ATTR_BACKGROUND_DRAWABLE)) {
    mBackGroundDrawableViews.add(new AttrEntity<View>(view,getAttr(mClass,attrs.getAttributeValue(i))));

代码示例来源:origin: stackoverflow.com

public CustomView(Context context, AttributeSet attrs) {
 super(context, attrs);
 String attrib1 = attrs.getAttributeValue(null, "attrib1");
 // do something with this value
}

代码示例来源:origin: GeekGhost/Ghost

public static int getAttributeValue(AttributeSet attr, int paramInt) {
  int value = -1;
  int count = attr.getAttributeCount();
  for (int i = 0; i < count; i++) {
    if (attr.getAttributeNameResource(i) == paramInt) {
      String str = attr.getAttributeValue(i);
      if (null != str && str.startsWith("?")) {
        value = Integer.valueOf(str.substring(1, str.length())).intValue();
        return value;
      }
    }
  }
  return value;
}

代码示例来源:origin: neopixl/PixlUI

/**
 * XML methods
 *
 * @param ctx
 * @param attrs
 */
@SuppressLint("NewApi")
private void setAllCaps(Context ctx, AttributeSet attrs) {
  if (!isInEditMode()) {
    int indexSize = attrs.getAttributeCount();
    boolean allCaps = false;
    for (int i = 0; i < indexSize; i++) {
      if (attrs.getAttributeName(i).equals(
          RADIOBUTTON_OS_ATTRIBUTE_TEXT_ALL_CAPS)) {
        allCaps = attrs.getAttributeBooleanValue(i, false);
        break;
      }
    }
    if (allCaps) {
      setAllCaps(allCaps);
    }
  }
}

代码示例来源:origin: stackoverflow.com

String fname = attrs.getAttributeValue(null, "class");
TypedArray a =  context.obtainStyledAttributes(attrs, FragmentTag.Fragment);
if (fname == null) {
  throw new IllegalArgumentException(attrs.getPositionDescription()
      + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
  throw new IllegalArgumentException(attrs.getPositionDescription()
      + ": Duplicate id 0x" + Integer.toHexString(id)
      + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)

代码示例来源:origin: navasmdc/MaterialDesignLibrary

int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
    "background", -1);
if (bacgroundColor != -1) {
  int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
  if (background != -1)
    setBackgroundColor(background);
final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
    "check", false);
  post(new Runnable() {
int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1);
String text = null;
  text = getResources().getString(textResource);
} else {
  text = attrs.getAttributeValue(ANDROIDXML, "text");

代码示例来源:origin: navasmdc/MaterialDesignLibrary

int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1);
if(textResource != -1){
  text = getResources().getString(textResource);
}else{
  text = attrs.getAttributeValue(ANDROIDXML,"text");
  addView(textButton);
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
  setBackgroundColor(getResources().getColor(bacgroundColor));
  background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
  if (background != -1)
    setBackgroundColor(background);

代码示例来源:origin: navasmdc/MaterialDesignLibrary

int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
  setBackgroundColor(getResources().getColor(bacgroundColor));
  background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
  if (background != -1)
    setBackgroundColor(background);
String value = attrs.getAttributeValue(ANDROIDXML,"padding");
int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1);
if(textResource != -1){
  text = getResources().getString(textResource);
}else{
  text = attrs.getAttributeValue(ANDROIDXML,"text");
  int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1);
  if(textColor != -1){
    textButton.setTextColor(textColor);
    textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1);
    if (textColor != -1)
      textButton.setTextColor(textColor);
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML,
    "rippleSpeed", Utils.dpToPx(6, getResources()));

代码示例来源:origin: square/assertj-android

public AttributeSetAssert hasAttributeCount(int count) {
 isNotNull();
 int actualCount = actual.getAttributeCount();
 assertThat(actualCount) //
   .overridingErrorMessage("Expected attribute count <%s> but was <%s>.", count,
     actualCount) //
   .isEqualTo(count);
 return this;
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

protected void setAttributes(AttributeSet attrs){
  int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
  if(bacgroundColor != -1){
    setBackgroundColor(getResources().getColor(bacgroundColor));
  }else{
    background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
    if (background != -1)
      setBackgroundColor(background);
  int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML,
      "rippleColor", -1);
  if (rippleColor != -1) {
  } else {
    int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);
    if (background != -1)
      setRippleColor(background);
  int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1);
  if(iconResource != -1)
    drawableIcon = getResources().getDrawable(iconResource);
  final boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", false);
    post(new Runnable() {

代码示例来源:origin: robolectric/robolectric

@Test
public void getAttributeValue_byName_shouldReturnValueFromAttribute() throws Exception {
 AttributeSet roboAttributeSet = Robolectric.buildAttributeSet()
   .addAttribute(R.attr.isSugary, "oh heck yeah")
   .build();
 assertThat(roboAttributeSet.getAttributeValue(APP_NS, "isSugary"))
   .isEqualTo("false");
 assertThat(roboAttributeSet.getAttributeBooleanValue(APP_NS, "isSugary", true))
   .isEqualTo(false);
 assertThat(roboAttributeSet.getAttributeBooleanValue(APP_NS, "animalStyle", true))
   .isEqualTo(true);
}

代码示例来源: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: qiujuer/Genius-Android

/**
 * Get the attribute have enabled value
 * Form android styles namespace
 *
 * @param attrs        AttributeSet
 * @param attribute    The attribute to retrieve
 * @param defaultValue What to return if the attribute isn't found
 * @return Resulting value
 */
public static boolean isTrueFromAttribute(AttributeSet attrs, String attribute, boolean defaultValue) {
  return attrs.getAttributeBooleanValue(Ui.androidStyleNameSpace, attribute, defaultValue);
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1);
if(bacgroundColor != -1){
  setBackgroundColor(getResources().getColor(bacgroundColor));
}else{
  int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
  if (background != -1)
    setBackgroundColor(background);
min = attrs.getAttributeIntValue(MATERIALDESIGNXML,"min", 0);
max = attrs.getAttributeIntValue(MATERIALDESIGNXML,"max", 100);
progress = attrs.getAttributeIntValue(MATERIALDESIGNXML,"progress", min);

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Returns the value of the min attribute, or its default value if not specified
 * <p>
 * This method should only be called once from the constructor.
 */
private int getMinFromAttributes(AttributeSet attrs) {
  return attrs == null ? 0 : attrs.getAttributeIntValue(AnkiDroidApp.XML_CUSTOM_NAMESPACE, "min", 0);
}

代码示例来源:origin: square/assertj-android

public AttributeSetAssert hasPositionDescription(String position) {
 isNotNull();
 String actualPosition = actual.getPositionDescription();
 assertThat(actualPosition) //
   .overridingErrorMessage("Expected position description <%s> but was <%s>.", position,
     actualPosition) //
   .isEqualTo(position);
 return this;
}

相关文章