当前位置: 首页>>代码示例>>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;未经允许,请勿转载。