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

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

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

Context.getString介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

/**
 * Creates a new instance enabling the given repeat toggle modes.
 *
 * @param context The context.
 * @param player The player on which to toggle the repeat mode.
 * @param repeatToggleModes The toggle modes to enable.
 */
public RepeatModeActionProvider(Context context, Player player,
  @RepeatModeUtil.RepeatToggleModes int repeatToggleModes) {
 this.player = player;
 this.repeatToggleModes = repeatToggleModes;
 repeatAllDescription = context.getString(R.string.exo_media_action_repeat_all_description);
 repeatOneDescription = context.getString(R.string.exo_media_action_repeat_one_description);
 repeatOffDescription = context.getString(R.string.exo_media_action_repeat_off_description);
}

代码示例来源:origin: square/leakcanary

private void requestWritePermissionNotification() {
 if (permissionNotificationDisplayed) {
  return;
 }
 permissionNotificationDisplayed = true;
 PendingIntent pendingIntent = RequestStoragePermissionActivity.createPendingIntent(context);
 String contentTitle = context.getString(R.string.leak_canary_permission_notification_title);
 CharSequence packageName = context.getPackageName();
 String contentText =
   context.getString(R.string.leak_canary_permission_notification_text, packageName);
 showNotification(context, contentTitle, contentText, pendingIntent, 0xDEAFBEEF);
}

代码示例来源:origin: pockethub/PocketHub

@Provides
Account account(Context context) {
  AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
  Account[] accounts = accountManager.getAccountsByType(context.getString(R.string.account_type));
  return accounts[0];
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * Set the title dialog. Default is "Permissions Required".
 */
@NonNull
public Builder setTitle(@StringRes int title) {
  mTitle = mContext.getString(title);
  return this;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * Set the rationale dialog. Default is
 * "This app may not work correctly without the requested permissions.
 * Open the app settings screen to modify app permissions."
 */
@NonNull
public Builder setRationale(@StringRes int rationale) {
  mRationale = mContext.getString(rationale);
  return this;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * Set the positive button text, default is {@link android.R.string#ok}.
 */
@NonNull
public Builder setPositiveButton(@StringRes int textId) {
  mPositiveButtonText = mContext.getString(textId);
  return this;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * Set the negative button text, default is {@link android.R.string#cancel}.
 */
@NonNull
public Builder setNegativeButton(@StringRes int textId) {
  mNegativeButtonText = mContext.getString(textId);
  return this;
}

代码示例来源:origin: google/ExoPlayer

public PlayerManager(Context context) {
 String adTag = context.getString(R.string.ad_tag_url);
 adsLoader = new ImaAdsLoader(context, Uri.parse(adTag));
 dataSourceFactory =
   new DefaultDataSourceFactory(
     context, Util.getUserAgent(context, context.getString(R.string.application_name)));
}

代码示例来源:origin: roughike/BottomBar

@NonNull
private String getTitleValue(@NonNull XmlResourceParser parser, @IntRange(from = 0) int attrIndex) {
  int titleResource = parser.getAttributeResourceValue(attrIndex, 0);
  return titleResource == RESOURCE_NOT_FOUND
      ? parser.getAttributeValue(attrIndex) : context.getString(titleResource);
}

代码示例来源:origin: JakeWharton/butterknife

private static @Nullable Unbinder parseBindString(Object target, Field field, View source) {
 BindString bindString = field.getAnnotation(BindString.class);
 if (bindString == null) {
  return null;
 }
 validateMember(field);
 int id = bindString.value();
 Context context = source.getContext();
 Class<?> fieldType = field.getType();
 Object value;
 if (fieldType == String.class) {
  value = context.getString(id);
 } else {
  throw new IllegalStateException(); // TODO
 }
 trySet(field, target, value);
 return Unbinder.EMPTY;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * @param resId the string resource to be used as a rationale
 * @see #setRationale(String)
 */
@NonNull
public Builder setRationale(@StringRes int resId) {
  mRationale = mHelper.getContext().getString(resId);
  return this;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * @see #setPositiveButtonText(String)
 */
@NonNull
public Builder setPositiveButtonText(@StringRes int resId) {
  mPositiveButtonText = mHelper.getContext().getString(resId);
  return this;
}

代码示例来源:origin: googlesamples/easypermissions

/**
 * @see #setNegativeButtonText(String)
 */
@NonNull
public Builder setNegativeButtonText(@StringRes int resId) {
  mNegativeButtonText = mHelper.getContext().getString(resId);
  return this;
}

代码示例来源:origin: lingochamp/FileDownloader

private Notification buildDefaultNotification(Context context) {
  String title = context.getString(R.string.default_filedownloader_notification_title);
  String content =
      context.getString(R.string.default_filedownloader_notification_content);
  Notification.Builder builder = new Notification.Builder(context, notificationChannelId);
  builder.setContentTitle(title).setContentText(content)
      .setSmallIcon(DEFAULT_NOTIFICATION_ID);
  return builder.build();
}

代码示例来源:origin: zhihu/Matisse

@Override
public IncapableCause filter(Context context, Item item) {
  if (!needFiltering(context, item))
    return null;
  Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri());
  if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) {
    return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth,
        String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize))));
  }
  return null;
}

代码示例来源:origin: google/ExoPlayer

@Override
public void onPlayerError(ExoPlaybackException exception) {
 Callback callback = getCallback();
 if (errorMessageProvider != null) {
  Pair<Integer, String> errorMessage = errorMessageProvider.getErrorMessage(exception);
  callback.onError(LeanbackPlayerAdapter.this, errorMessage.first, errorMessage.second);
 } else {
  callback.onError(LeanbackPlayerAdapter.this, exception.type, context.getString(
    R.string.lb_media_player_error, exception.type, exception.rendererIndex));
 }
}

代码示例来源:origin: android10/Android-CleanArchitecture

public void testNetworkConnectionErrorMessage() {
 String expectedMessage = getContext().getString(R.string.exception_message_no_connection);
 String actualMessage = ErrorMessageFactory.create(getContext(),
   new NetworkConnectionException());
 assertThat(actualMessage, is(equalTo(expectedMessage)));
}

代码示例来源:origin: android10/Android-CleanArchitecture

public void testUserNotFoundErrorMessage() {
  String expectedMessage = getContext().getString(R.string.exception_message_user_not_found);
  String actualMessage = ErrorMessageFactory.create(getContext(), new UserNotFoundException());

  assertThat(actualMessage, is(equalTo(expectedMessage)));
 }
}

代码示例来源:origin: JakeWharton/butterknife

@Test public void simpleInt() {
  Target target = new Target();
  String expected = context.getString(R.string.hey);

  Unbinder unbinder = new BindStringTest$Target_ViewBinding(target, context);
  assertThat(target.actual).isEqualTo(expected);

  unbinder.unbind();
  assertThat(target.actual).isEqualTo(expected);
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getResourcesForApplication_currentApplication() throws Exception {
 assertThat(
     packageManager
       .getResourcesForApplication("org.robolectric")
       .getString(R.string.app_name))
   .isEqualTo(ApplicationProvider.getApplicationContext().getString(R.string.app_name));
}

相关文章

微信公众号

最新文章

更多

Context类方法