當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。