android.content.res.Resources.getXml()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(166)

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

Resources.getXml介绍

暂无

代码示例

代码示例来源:origin: roughike/BottomBar

TabParser(@NonNull Context context, @NonNull BottomBarTab.Config defaultTabConfig, @XmlRes int tabsXmlResId) {
  this.context = context;
  this.defaultTabConfig = defaultTabConfig;
  this.parser = context.getResources().getXml(tabsXmlResId);
}

代码示例来源:origin: android-hacker/VirtualXposed

public XmlResourceParser getParser(Context context, ServiceInfo serviceInfo, String name) {
  Bundle meta = serviceInfo.metaData;
  if (meta != null) {
    int xmlId = meta.getInt(name);
    if (xmlId != 0) {
      try {
        return getResources(context, serviceInfo.applicationInfo).getXml(xmlId);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  return null;
}

代码示例来源:origin: zwwill/yanxuan-weex-demo

public synchronized void parse(Context action) {
 // First checking the class namespace for config.xml
 int id = action.getResources().getIdentifier("app_config", "xml", action.getClass().getPackage()
   .getName());
 if (id == 0) {
  // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml
  id = action.getResources().getIdentifier("app_config", "xml", action.getPackageName());
  if (id == 0) {
   Log.e(TAG, "res/xml/app_config.xml is missing!");
   return;
  }
 }
 parse(action.getResources().getXml(id));
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void subscribe(ObservableEmitter<String> emitter) {
  try {
   XmlPullParser xpp=resources.getXml(R.xml.words);
   while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) {
    if (xpp.getEventType()==XmlPullParser.START_TAG) {
     if (xpp.getName().equals("word")) {
      emitter.onNext(xpp.getAttributeValue(0));
     }
    }
    xpp.next();
   }
   emitter.onComplete();
  }
  catch (Exception e) {
   emitter.onError(e);
  }
 }
}

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

@Test(expected = Resources.NotFoundException.class)
public void testGetXml_nonxmlfile() {
 resources.getXml(R.drawable.an_image);
}

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

@Test(expected = Resources.NotFoundException.class)
public void testGetXml_nonexistentResource() {
 resources.getXml(0);
}

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

@Test
public void obtainAttributes_shouldReturnValuesFromResources() throws Exception {
 XmlPullParser parser = resources.getXml(R.xml.xml_attrs);
 parser.next();
 parser.next();
 AttributeSet attributes = Xml.asAttributeSet(parser);
 TypedArray typedArray = resources
   .obtainAttributes(attributes, new int[]{android.R.attr.title, android.R.attr.scrollbarFadeDuration});
 assertThat(typedArray.getString(0)).isEqualTo("Android Title");
 assertThat(typedArray.getInt(1, 0)).isEqualTo(1111);
 typedArray.recycle();
}

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

@Test
public void getXml_withNonFile_throwsNotFoundException() throws Exception {
 try {
  resources.getXml(R.string.hello);
  fail("should throw");
 } catch (Resources.NotFoundException e) {
  // cool
 }
 try {
  resources.getXml(-1234);
  fail("should throw");
 } catch (Resources.NotFoundException e) {
  // cool
 }
}

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

@Test
 public void getXml_shouldHavePackageContextForReferenceResolution() throws Exception {
  if (!useLegacy()) {
   return;
  }
  XmlResourceParserImpl xmlResourceParser =
    (XmlResourceParserImpl) resources.getXml(R.xml.preferences);
  assertThat(xmlResourceParser.qualify("?ref")).isEqualTo("?org.robolectric:attr/ref");

  xmlResourceParser =
    (XmlResourceParserImpl) resources.getXml(android.R.layout.list_content);
  assertThat(xmlResourceParser.qualify("?ref")).isEqualTo("?android:attr/ref");
 }
}

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

@Before
public void setUp() throws Exception {
 context = ApplicationProvider.getApplicationContext();
 parser = context.getResources().getXml(R.xml.preferences);
}

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

private XmlResourceParser getFirstElementAttrSet(int resId) throws Exception {
 XmlResourceParser xml = resources.getXml(resId);
 assertThat(xml.next()).isEqualTo(XmlPullParser.START_DOCUMENT);
 assertThat(xml.nextTag()).isEqualTo(XmlPullParser.START_TAG);
 return (XmlResourceParser) Xml.asAttributeSet(xml);
}

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

@Test
public void obtainStyledAttributes_shouldCheckXmlFirst_fromXmlLoadedFromResources() throws Exception {
 // This simulates a ResourceProvider built from a 21+ SDK as viewportHeight / viewportWidth were introduced in API 21
 // but the public ID values they are assigned clash with private com.android.internal.R values on older SDKs. This
 // test ensures that even on older SDKs, on calls to obtainStyledAttributes() Robolectric will first check for matching
 // resource ID values in the AttributeSet before checking the theme.
 XmlResourceParser xml = context.getResources().getXml(R.drawable.vector);
 xml.next();
 xml.next();
 AttributeSet attributeSet = Xml.asAttributeSet(xml);
 TypedArray typedArray = context.getTheme().obtainStyledAttributes(attributeSet, new int[] {
   android.R.attr.viewportWidth,
   android.R.attr.viewportHeight
 }, 0, 0);
 assertThat(typedArray.getFloat(0, 0)).isEqualTo(12.0f);
 assertThat(typedArray.getFloat(1, 0)).isEqualTo(24.0f);
 typedArray.recycle();
}

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

@Test
public void testGetXml() throws Exception {
 XmlResourceParser parser = resources.getXml(R.xml.preferences);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("PreferenceScreen");
 parser = resources.getXml(R.layout.custom_layout);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("org.robolectric.android.CustomView");
 parser = resources.getXml(R.menu.test);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("menu");
 parser = resources.getXml(R.drawable.rainbow);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("layer-list");
 parser = resources.getXml(R.anim.test_anim_1);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("set");
 parser = resources.getXml(R.color.color_state_list);
 assertThat(parser).isNotNull();
 assertThat(findRootTag(parser)).isEqualTo("selector");
}

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

@Test
public void whenMissingXml_throwNotFoundException() throws Exception {
 try {
  resources.getXml(0x3038);
  fail();
 } catch (Resources.NotFoundException e) {
  assertThat(e.getMessage()).contains("Resource ID #0x3038");
 }
}

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

@Test
public void testGetAttributeResourceValueIntInt() throws Exception {
 parser = context.getResources().getXml(R.xml.has_attribute_resource_value);
 parseUntilNext(XmlResourceParser.START_TAG);
 assertThat(parser.getAttributeResourceValue(0, 42)).isEqualTo(R.layout.main);
}

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

@Test
public void getStyleAttribute_allowStyleAttrReferenceLackingExplicitAttrType() throws Exception {
 parser = context.getResources().getXml(R.xml.has_parent_style_reference);
 parseUntilNext(XmlResourceParser.START_TAG);
 assertThat(parser.getStyleAttribute()).isEqualTo(R.attr.parentStyleReference);
}

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

@Test
public void getStyleAttribute_allowStyleAttrReference() throws Exception {
 parser = context.getResources().getXml(R.xml.has_style_attribute_reference);
 parseUntilNext(XmlResourceParser.START_TAG);
 assertThat(parser.getStyleAttribute()).isEqualTo(R.attr.parentStyleReference);
}

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

@Test
public void testGetAttributeResourceValueStringStringInt() throws Exception {
 parser = context.getResources().getXml(R.xml.has_attribute_resource_value);
 parseUntilNext(XmlResourceParser.START_TAG);
 assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "bar", 42)).isEqualTo(R.layout.main);
 assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "foo", 42)).isEqualTo(42);
}

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

@Test
public void getXml() throws Exception {
 XmlResourceParser xmlResourceParser = resources.getXml(R.xml.preferences);
 assertThat(xmlResourceParser).isNotNull();
 assertThat(xmlResourceParser.next()).isEqualTo(XmlResourceParser.START_DOCUMENT);
 assertThat(xmlResourceParser.next()).isEqualTo(XmlResourceParser.START_TAG);
 assertThat(xmlResourceParser.getName()).isEqualTo("PreferenceScreen");
}

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

@Test
public void testGetIdAttributeResourceValue_defaultValue() throws Exception {
 assertThat(parser.getIdAttributeResourceValue(12)).isEqualTo(12);
 parser = context.getResources().getXml(R.xml.has_id);
 parseUntilNext(XmlResourceParser.START_TAG);
 assertThat(parser.getIdAttributeResourceValue(12)).isEqualTo(R.id.tacos);
}

相关文章

微信公众号

最新文章

更多