android.content.Context.getColor()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中android.content.Context.getColor()方法的一些代码示例,展示了Context.getColor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getColor()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getColor

Context.getColor介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

@SuppressWarnings("deprecation")
public static int getColor(@NonNull Context context, @ColorRes int colorId) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    return context.getColor(colorId);
  }
  return context.getResources().getColor(colorId);
}

代码示例来源:origin: zzz40500/android-shapeLoadingView

private int getColor(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return context.getColor(id);
    } else {
      return context.getResources().getColor(id);
    }
  }
}

代码示例来源:origin: team-supercharge/ShimmerLayout

private int getColor(int id) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    return getContext().getColor(id);
  } else {
    //noinspection deprecation
    return getResources().getColor(id);
  }
}

代码示例来源:origin: sharish/ShimmerRecyclerView

private int getColor(int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return getContext().getColor(id);
    } else {
      return getResources().getColor(id);
    }
  }
}

代码示例来源:origin: rockerhieu/emojicon

private void addTabDivider() {
  View divider = new View(getContext());
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    mViewPager.setBackgroundColor(getContext().getResources().getColor(R.color.horizontal_vertical));
  } else {
    mViewPager.setBackgroundColor(getContext().getColor(R.color.horizontal_vertical));
  }
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT);
  mTabsContainer.addView(divider, mTabsContainer.getChildCount() - 2, params);
}

代码示例来源:origin: ukanth/afwall

public void update(String e, Boolean success){
    errorText.setText(e);
    if(success){
      errorText.setTextColor(getContext().getColor(R.color.dark_bg));
      triggerSuccess();
    }
  }
}

代码示例来源:origin: CaMnter/AndroidLife

public static int getColor(Context context, int id) {
    return context.getColor(id);
  }
}

代码示例来源:origin: ValleZ/Paper-Wallet

private static int getColor(Context context, int id) {
  if (Build.VERSION.SDK_INT >= 23) {
    return context.getColor(id);
  } else {
    //noinspection deprecation
    return context.getResources().getColor(id);
  }
}

代码示例来源:origin: Microsoft/AppCenter-SDK-Android

@SuppressWarnings("deprecation")
  private static int getColor(Context context, int colorResourceId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return context.getColor(colorResourceId);
    } else {
      return context.getResources().getColor(colorResourceId);
    }
  }
}

代码示例来源:origin: TakeoffAndroid/AndroidMVPAuthenticationBoilerPlate

public static int getColor(Context context,int color ){
  if(Build.VERSION.SDK_INT >= 23){
    return context.getColor(color);
  }
  return context.getResources().getColor(color);
}

代码示例来源:origin: Drippler/drip-steps

static public int getColor(Context context, int resourceId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return context.getColor(resourceId);
    } else {
      //noinspection deprecation
      return context.getResources().getColor(resourceId);
    }
  }
}

代码示例来源:origin: tuacy/RecyclerPinnedHeader

public static int getColor(Context context, @ColorRes int colorId) {
  if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
    //noinspection deprecation
    return context.getResources().getColor(colorId);
  } else {
    return context.getColor(colorId);
  }
}

代码示例来源:origin: sorz/TinyKeePass

@Override
  public void run() {
    imageFingerprintIcon.setImageResource(R.mipmap.ic_fp_40px);
    textFingerprintStatus.setText(R.string.fingerprint_hint);
    textFingerprintStatus.setTextColor(context.getColor(R.color.hint));
  }
};

代码示例来源:origin: GuilhE/android-circular-progress-view

/**
 * You can simulate the use of this method with by calling {@link #setColor(int)} with ContextCompat:
 * setBackgroundColor(ContextCompat.getColor(resId));
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public void setColorResource(@ColorRes int resId) {
  setColor(getContext().getColor(resId));
}

代码示例来源:origin: mike14u/shimmer-recyclerview-x

private int getColor(int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return getContext().getColor(id);
    } else {
      return getResources().getColor(id);
    }
  }
}

代码示例来源:origin: hiteshbpatel/Android_Blog_Projects

private int getColor(int id) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    return getContext().getColor(id);
  } else {
    //noinspection deprecation
    return getResources().getColor(id);
  }
}

代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE

public ForumListAdapter(Context context, List<ForumsListModel.Forum> list) {
  mContext = context;
  mLayoutInflater = LayoutInflater.from(mContext);
  mList = list;
  mColor = mContext.getColor(ThemeManager.getInstance().getForegroundColor());
}

代码示例来源:origin: cbeyls/fosdem-companion-android

@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
  NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
  NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
      context.getString(R.string.notification_events_channel_name),
      NotificationManager.IMPORTANCE_HIGH);
  channel.setShowBadge(false);
  channel.setLightColor(context.getColor(R.color.color_primary));
  channel.enableVibration(true);
  channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
  notificationManager.createNotificationChannel(channel);
}

代码示例来源:origin: Omico/CurrentActivity

private void initLayout(ViewGroup viewGroup, @LayoutRes int layout, @StringRes int title, boolean nextButtonEnable) {
    View inflate = LayoutInflater.from(this).inflate(layout, viewGroup, false);
    viewGroup.addView(inflate);
    getSetupWizardLayout().setHeaderText(title);
    getSetupWizardLayout().getHeaderTextView().setTextColor(viewGroup.getContext().getColor(R.color.colorAccent));
    setNavigationBarNextButtonEnabled(nextButtonEnable);
  }
}

代码示例来源:origin: Microsoft/AppCenter-SDK-Android

@Test
public void handleNotificationWithDefaultColor() {
  int resourceId = 42;
  int color = 0x424242;
  Bundle bundle = mock(Bundle.class);
  when(bundle.getInt(DEFAULT_COLOR_METADATA_NAME)).thenReturn(resourceId);
  mApplicationInfoMock.metaData = bundle;
  when(mContextMock.getColor(eq(resourceId))).thenReturn(color);
  PushNotifier.handleNotification(mContextMock, new Intent());
  verify(mNotificationBuilderMock).setColor(eq(color));
  verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock);
}

相关文章

Context类方法