當前位置: 首頁>>代碼示例>>Java>>正文


Java Resources.getIdentifier方法代碼示例

本文整理匯總了Java中android.content.res.Resources.getIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getIdentifier方法的具體用法?Java Resources.getIdentifier怎麽用?Java Resources.getIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.Resources的用法示例。


在下文中一共展示了Resources.getIdentifier方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAppIdFromResource

import android.content.res.Resources; //導入方法依賴的package包/類
static String getAppIdFromResource(Context ctx) {
    try {
        Resources res = ctx.getResources();
        String pkgName = ctx.getPackageName();
        int res_id = res.getIdentifier("app_id", "string", pkgName);
        return res.getString(res_id);
    } catch (Exception ex) {
        ex.printStackTrace();
        return "??? (failed to retrieve APP ID)";
    }
}
 
開發者ID:TheAndroidMaster,項目名稱:Asteroid,代碼行數:12,代碼來源:GameHelperUtils.java

示例2: handleInstallShortcutIntent

import android.content.res.Resources; //導入方法依賴的package包/類
private Intent handleInstallShortcutIntent(Intent intent) {
    Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (shortcut != null) {
        ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
        if (component != null) {
            String pkg = component.getPackageName();
            Intent newShortcutIntent = new Intent();
            newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
            newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
            newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
            newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
            newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
            intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);

            Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
                try {
                    Resources resources = VirtualCore.get().getResources(pkg);
                    int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
                    if (resId > 0) {
                        //noinspection deprecation
                        Drawable iconDrawable = resources.getDrawable(resId);
                        Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
                        if (newIcon != null) {
                            intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return intent;
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:38,代碼來源:MethodProxies.java

示例3: getNavBarHeight

import android.content.res.Resources; //導入方法依賴的package包/類
static int getNavBarHeight(Context c) {
    int result = 0;
    boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if (!hasMenuKey && !hasBackKey) {
        // The device has a navigation bar
        Resources res = c.getResources();

        int orientation = res.getConfiguration().orientation;
        int resourceId;
        if (isTablet(c)) {
            resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
        } else {
            resourceId = res.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android");
        }
        if (resourceId > 0) {
            return res.getDimensionPixelSize(resourceId);
        }
    }
    return result;
}
 
開發者ID:tylersuehr7,項目名稱:chips-input-layout,代碼行數:23,代碼來源:Utils.java

示例4: getInternalDimensionSize

import android.content.res.Resources; //導入方法依賴的package包/類
private int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }
    return result;
}
 
開發者ID:chengkun123,項目名稱:ReadMark,代碼行數:9,代碼來源:SystemBarTintManager.java

示例5: getNavigationBarHeight

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 獲取底部導航欄高度
 * @param activity
 * @return
 */
public static int getNavigationBarHeight(Context activity) {
    if (!checkDeviceHasNavigationBar(activity)) {
        return 0;
    }
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height",
            "dimen", "android");
    //獲取NavigationBar的高度
    int height = resources.getDimensionPixelSize(resourceId);
    return height;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:NavUtils.java

示例6: getSpokenDescriptionId

import android.content.res.Resources; //導入方法依賴的package包/類
private int getSpokenDescriptionId(final Context context, final int code,
        final String resourceNameFormat) {
    final String resourceName = String.format(Locale.ROOT, resourceNameFormat, code);
    final Resources resources = context.getResources();
    // Note that the resource package name may differ from the context package name.
    final String resourcePackageName = resources.getResourcePackageName(
            R.string.spoken_description_unknown);
    final int resId = resources.getIdentifier(resourceName, "string", resourcePackageName);
    if (resId != 0) {
        mKeyCodeMap.append(code, resId);
    }
    return resId;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:14,代碼來源:KeyCodeDescriptionMapper.java

示例7: setQuestion

import android.content.res.Resources; //導入方法依賴的package包/類
private void setQuestion(int n) {

        // Get all questions array from strings resource
        Resources res = getResources();
        String[] questions = res.getStringArray(R.array.questions);

        // Get possible answers array for current question from strings resource
        int resIdAnswers =
                res.getIdentifier("answers_for_question_" + (n + 1), "array", this.getPackageName());
        answers = res.getStringArray(resIdAnswers);

        // Get correct answers from strings resource
        String[] correctAnswers = res.getStringArray(R.array.correct_answers_radiobuttons);

        question = new Question(questions[n], answers, correctAnswers[n]);

        // Set text of question
        TextView questionTextView = (TextView) findViewById(R.id.text_question);
        questionTextView.setText(questions[n]);

        // Set text of answers radio buttons
        radioGroup = (RadioGroup) findViewById(R.id.radio_group);

        for (int i = 0; i < radioGroup.getChildCount(); i++) {
            ((RadioButton) radioGroup.getChildAt(i)).setText(answers[i]);
        }
    }
 
開發者ID:PascalR2014,項目名稱:Epilepsy_quiz,代碼行數:28,代碼來源:QuestionActivity.java

示例8: getNavBarHeight

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 獲取導航欄高度
 * <p>0代表不存在</p>
 *
 * @return 導航欄高度
 */
public static int getNavBarHeight() {
    boolean hasMenuKey = ViewConfiguration.get(Utils.getContext()).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    if (!hasMenuKey && !hasBackKey) {
        Resources res = Utils.getContext().getResources();
        int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
        return res.getDimensionPixelSize(resourceId);
    } else {
        return 0;
    }
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:18,代碼來源:BarUtils.java

示例9: getInternalDimensionSize

import android.content.res.Resources; //導入方法依賴的package包/類
private static int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }
    return result;
}
 
開發者ID:SiberiaDante,項目名稱:TitleLayout,代碼行數:9,代碼來源:ScreenUtil.java

示例10: getStatusBarHeight

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * Unfortunately Android doesn't have an official API to retrieve the height of
 * StatusBar. This is just receiver way to hack around, may not work on some devices.
 *
 * @return The height of StatusBar.
 */
public int getStatusBarHeight() {
    Activity activity = getActivity();
    if (activity == null) return 0;

    Resources resources  = getActivity().getResources();
    int       result     = 0;
    int       resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = resources.getDimensionPixelSize(resourceId);
    }
    LogUtils.v("getStatusBarHeight: " + result);
    return result;
}
 
開發者ID:guzhigang001,項目名稱:QNewsDemo,代碼行數:20,代碼來源:ActivityUtils.java

示例11: getDrawableFromResourceUri

import android.content.res.Resources; //導入方法依賴的package包/類
Drawable getDrawableFromResourceUri(Uri uri) throws FileNotFoundException {
    String authority = uri.getAuthority();
    if (TextUtils.isEmpty(authority)) {
        throw new FileNotFoundException("No authority: " + uri);
    }
    try {
        Resources r = this.mContext.getPackageManager().getResourcesForApplication(authority);
        List<String> path = uri.getPathSegments();
        if (path == null) {
            throw new FileNotFoundException("No path: " + uri);
        }
        int id;
        int len = path.size();
        if (len == 1) {
            try {
                id = Integer.parseInt((String) path.get(0));
            } catch (NumberFormatException e) {
                throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
            }
        } else if (len == 2) {
            id = r.getIdentifier((String) path.get(1), (String) path.get(0), authority);
        } else {
            throw new FileNotFoundException("More than two path segments: " + uri);
        }
        if (id != 0) {
            return r.getDrawable(id);
        }
        throw new FileNotFoundException("No resource found for: " + uri);
    } catch (NameNotFoundException e2) {
        throw new FileNotFoundException("No package found for authority: " + uri);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:33,代碼來源:SuggestionsAdapter.java

示例12: getPluginResourceId

import android.content.res.Resources; //導入方法依賴的package包/類
public static int getPluginResourceId(Context context, String apkPath, int oldResourceId) {

        Resources resources = context.getResources();
        String colorName = resources.getResourceName(oldResourceId);
        String entryName = resources.getResourceEntryName(oldResourceId);
        String typeName = resources.getResourceTypeName(oldResourceId);

        Log.e("MyLog", colorName + "," + entryName + "," + typeName);

        Resources pluginResources = resourcesMap.get(apkPath);
        if (pluginResources == null) {

            pluginResources = RecourcesUtil.getResources(context, apkPath);

            resourcesMap.put(apkPath, pluginResources);

        }

        String packageName = SPluginUtil.getPackageInfo(context, apkPath).packageName;
        int colorId = pluginResources.getIdentifier(entryName, typeName, packageName);
        Log.e("MyLog", colorId + "");


        return colorId;

    }
 
開發者ID:XaskYSab,項目名稱:CSkin,代碼行數:27,代碼來源:RecourcesUtil.java

示例13: getStatusBarHeight

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 獲取狀態欄高度(px)
 *
 * @return 狀態欄高度px
 */
public static int getStatusBarHeight() {
    Resources resources = Utils.getApp().getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    return resources.getDimensionPixelSize(resourceId);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:BarUtils.java

示例14: shouldLoadAllEmojis

import android.content.res.Resources; //導入方法依賴的package包/類
@Test
public void shouldLoadAllEmojis() throws Exception {

    final Context context = InstrumentationRegistry.getTargetContext();

    final Resources resources = context.getResources();
    final String[] emojiArray = resources.getStringArray(R.array.emoji_name_array);


    for (String emoji : emojiArray) {
        final int resourceId = resources.getIdentifier(String.format("emoji_%s", emoji), "drawable",
                context.getPackageName());

        assertNotNull(String.format("emoji %s should not be null", emoji), context.getDrawable(resourceId));

    }

}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:19,代碼來源:EmojiLoadTest.java

示例15: getResId

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 根據資源名稱獲取資源的id
 * 
 * @param mContext
 * @param name
 * @param defType
 * @return
 */
private static int getResId(String name, String defType)
{
	String pageName = GlobalState.getInstance().getApplicationContext().getPackageName();
    Resources mResources = GlobalState.getInstance().getResources();
    return mResources.getIdentifier(name, defType, pageName);
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:15,代碼來源:MIP_R.java


注:本文中的android.content.res.Resources.getIdentifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。