本文整理匯總了Java中android.content.res.XmlResourceParser.getAttributeResourceValue方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlResourceParser.getAttributeResourceValue方法的具體用法?Java XmlResourceParser.getAttributeResourceValue怎麽用?Java XmlResourceParser.getAttributeResourceValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.XmlResourceParser
的用法示例。
在下文中一共展示了XmlResourceParser.getAttributeResourceValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getColorValue
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private Integer getColorValue(int attrIndex, XmlResourceParser parser) {
// Modify the >>>
String valueResource = parser.getAttributeValue(attrIndex);
if(!TextUtils.isEmpty(valueResource) && valueResource.startsWith("?")){ // 引用主題屬性
valueResource = valueResource.replace("?", "@"); // 替換?
int attr = context.getResources().getIdentifier(valueResource, "attr", context.getPackageName()); // 找出屬性Id
if(attr != 0){
TypedArray array = context.obtainStyledAttributes(new int[]{attr}); //解析屬性值
return array.getColor(0, 0);
}
}
// <<<
int colorResource = parser.getAttributeResourceValue(attrIndex, 0);
if (colorResource != 0) {
return ContextCompat.getColor(context, colorResource);
}
try {
return Color.parseColor(parser.getAttributeValue(attrIndex));
} catch (Exception ignored) {
return null;
}
}
示例2: getXmlAttribute
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Attempts to get the given attribute as a String resource first, and if it fails
* returns the attribute as a simple String value.
* @param xml
* @param name
* @return
*/
private String getXmlAttribute(XmlResourceParser xml, String name) {
int resId = xml.getAttributeResourceValue(null, name, 0);
if (resId == 0) {
return xml.getAttributeValue(null, name);
} else {
return getString(resId);
}
}
示例3: getAttributeResourceValue
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Return attribute resource value, attempting launcher-specific namespace
* first before falling back to anonymous attribute.
*/
static int getAttributeResourceValue(XmlResourceParser parser, String attribute,
int defaultValue) {
int value = parser.getAttributeResourceValue(
"http://schemas.android.com/apk/res-auto/com.enrico.launcher3", attribute,
defaultValue);
if (value == defaultValue) {
value = parser.getAttributeResourceValue(null, attribute, defaultValue);
}
return value;
}
示例4: getAttributeResourceValue
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Return attribute resource value, attempting launcher-specific namespace
* first before falling back to anonymous attribute.
*/
protected static int getAttributeResourceValue(XmlResourceParser parser, String attribute,
int defaultValue) {
int value = parser.getAttributeResourceValue(
"http://schemas.android.com/apk/res-auto/com.android.launcher3", attribute,
defaultValue);
if (value == defaultValue) {
value = parser.getAttributeResourceValue(null, attribute, defaultValue);
}
return value;
}
示例5: loadLogoFromManifest
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Attempt to programmatically load the logo from the manifest file of an
* activity by using an XML pull parser. This should allow us to read the
* logo attribute regardless of the platform it is being run on.
*
* @param activity Activity instance.
* @return Logo resource ID.
*/
private static int loadLogoFromManifest(Activity activity) {
int logo = 0;
try {
final String thisPackage = activity.getClass().getName();
if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);
final String packageName = activity.getApplicationInfo().packageName;
final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("application".equals(name)) {
//Check if the <application> has the attribute
if (DEBUG) Log.d(TAG, "Got <application>");
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
if ("logo".equals(xml.getAttributeName(i))) {
logo = xml.getAttributeResourceValue(i, 0);
break; //out of for loop
}
}
} else if ("activity".equals(name)) {
//Check if the <activity> is us and has the attribute
if (DEBUG) Log.d(TAG, "Got <activity>");
Integer activityLogo = null;
String activityPackage = null;
boolean isOurActivity = false;
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
//We need both uiOptions and name attributes
String attrName = xml.getAttributeName(i);
if ("logo".equals(attrName)) {
activityLogo = xml.getAttributeResourceValue(i, 0);
} else if ("name".equals(attrName)) {
activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
if (!thisPackage.equals(activityPackage)) {
break; //on to the next
}
isOurActivity = true;
}
//Make sure we have both attributes before processing
if ((activityLogo != null) && (activityPackage != null)) {
//Our activity, logo specified, override with our value
logo = activityLogo.intValue();
}
}
if (isOurActivity) {
//If we matched our activity but it had no logo don't
//do any more processing of the manifest
break;
}
}
}
eventType = xml.nextToken();
}
} catch (Exception e) {
e.printStackTrace();
}
if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
return logo;
}
示例6: loadLogoFromManifest
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Attempt to programmatically load the logo from the manifest file of an
* activity by using an XML pull parser. This should allow us to read the
* logo attribute regardless of the platform it is being run on.
*
* @param activity Activity instance.
* @return Logo resource ID.
*/
public static int loadLogoFromManifest(Activity activity) {
int logo = 0;
try {
final String thisPackage = activity.getClass().getName();
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);
final String packageName = activity.getApplicationInfo().packageName;
final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("application".equals(name)) {
//Check if the <application> has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
if ("logo".equals(xml.getAttributeName(i))) {
logo = xml.getAttributeResourceValue(i, 0);
break; //out of for loop
}
}
} else if ("activity".equals(name)) {
//Check if the <activity> is us and has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
Integer activityLogo = null;
String activityPackage = null;
boolean isOurActivity = false;
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
//We need both uiOptions and name attributes
String attrName = xml.getAttributeName(i);
if ("logo".equals(attrName)) {
activityLogo = xml.getAttributeResourceValue(i, 0);
} else if ("name".equals(attrName)) {
activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
if (!thisPackage.equals(activityPackage)) {
break; //on to the next
}
isOurActivity = true;
}
//Make sure we have both attributes before processing
if ((activityLogo != null) && (activityPackage != null)) {
//Our activity, logo specified, override with our value
logo = activityLogo.intValue();
}
}
if (isOurActivity) {
//If we matched our activity but it had no logo don't
//do any more processing of the manifest
break;
}
}
}
eventType = xml.nextToken();
}
} catch (Exception e) {
e.printStackTrace();
}
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
return logo;
}
示例7: getTitleValue
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private String getTitleValue(int attrIndex, XmlResourceParser parser) {
int titleResource = parser.getAttributeResourceValue(attrIndex, 0);
if (titleResource != 0) {
return context.getString(titleResource);
}
return parser.getAttributeValue(attrIndex);
}