java语法中的“new int [] {some_value}”是什么意思

时间:2017-08-10 06:01:20

标签: java

public static int getThemeColor(Context context, int attribute, int defaultColor) {
    int themeColor = 0;
    String packageName = context.getPackageName();
    try {
        Context packageContext = context.createPackageContext(packageName, 0);
        ApplicationInfo applicationInfo =
            context.getPackageManager().getApplicationInfo(packageName, 0);
        packageContext.setTheme(applicationInfo.theme);
        Resources.Theme theme = packageContext.getTheme();
        TypedArray ta = theme.obtainStyledAttributes(new int[] {attribute});
        themeColor = ta.getColor(0, defaultColor);
        ta.recycle();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return themeColor;
}

我的问题是关于这一行:

TypedArray ta = theme.obtainStyledAttributes(new int[] {attribute});

new int[] {attribute}

1 个答案:

答案 0 :(得分:0)

new int[] {attribute}

初始化一个原始整数数组,其中一个元素和值设置为attribute

您还可以使用以下方法初始化原始整数数组:

int[] intArray = new int[2];
int[] intArray = {4,5};
int[] intArray = new int[]{4,5};

希望这有帮助。