当前位置: 首页>>代码示例>>Java>>正文


Java XmlResourceParser.getAttributeResourceValue方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:26,代码来源:TabParser.java

示例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);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:16,代码来源:AccountSetupBasics.java

示例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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:15,代码来源:AutoInstallsLayout.java

示例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;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:15,代码来源:AutoInstallsLayout.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:79,代码来源:Utility4.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:79,代码来源:ResourcesCompat.java

示例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);
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:10,代码来源:TabParser.java


注:本文中的android.content.res.XmlResourceParser.getAttributeResourceValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。