android.content.res.Resources类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(202)

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

Resources介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Resources res = context.getResources();
 // Change locale settings in the app.
 DisplayMetrics dm = res.getDisplayMetrics();
 android.content.res.Configuration conf = res.getConfiguration();
 conf.locale = new Locale(language_code.toLowerCase());
 res.updateConfiguration(conf, dm);

代码示例来源: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: MindorksOpenSource/android-mvp-architecture

public static void openPlayStoreForApp(Context context) {
  final String appPackageName = context.getPackageName();
  try {
    context.startActivity(new Intent(Intent.ACTION_VIEW,
        Uri.parse(context
            .getResources()
            .getString(R.string.app_market_link) + appPackageName)));
  } catch (android.content.ActivityNotFoundException e) {
    context.startActivity(new Intent(Intent.ACTION_VIEW,
        Uri.parse(context
            .getResources()
            .getString(R.string.app_google_play_store_link) + appPackageName)));
  }
}

代码示例来源:origin: airbnb/lottie-android

public static float dpScale() {
 if (dpScale == -1) {
  dpScale = Resources.getSystem().getDisplayMetrics().density;
 }
 return dpScale;
}

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

/** 获取状态栏高度 */
  public static int getStatusBarHeight(Context context) {
    int result = 24;
    int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resId > 0) {
      result = context.getResources().getDimensionPixelSize(resId);
    } else {
      result = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
          result, Resources.getSystem().getDisplayMetrics());
    }
    return result;
  }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

public void initList(List<SwitchVideoModel> data, OnListItemClickListener onItemClickListener) {
  this.onItemClickListener = onItemClickListener;
  this.data = data;
  LayoutInflater inflater = LayoutInflater.from(mContext);
  View view = inflater.inflate(R.layout.switch_video_dialog, null);
  listView = (ListView) view.findViewById(R.id.switch_dialog_list);
  setContentView(view);
  adapter = new ArrayAdapter<>(mContext, R.layout.switch_video_dialog_item, data);
  listView.setAdapter(adapter);
  listView.setOnItemClickListener(new OnItemClickListener());
  Window dialogWindow = getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  DisplayMetrics d = mContext.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
  lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
  dialogWindow.setAttributes(lp);
}

代码示例来源:origin: chentao0707/SimplifyReader

public void showNetworkError(View.OnClickListener onClickListener) {
  View layout = helper.inflate(R.layout.message);
  TextView textView = (TextView) layout.findViewById(R.id.message_info);
  textView.setText(helper.getContext().getResources().getString(R.string.common_no_network_msg));
  ImageView imageView = (ImageView) layout.findViewById(R.id.message_icon);
  imageView.setImageResource(R.drawable.ic_exception);
  if (null != onClickListener) {
    layout.setOnClickListener(onClickListener);
  }
  helper.showLayout(layout);
}

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

@Override
protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final View thisView = this;
  if (thisView.isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题
    int d = DensityUtil.dp2px(5);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(0xcccccccc);
    paint.setStrokeWidth(DensityUtil.dp2px(1));
    paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
    canvas.drawRect(d, d, thisView.getWidth() - d, thisView.getBottom() - d, paint);
    TextView textView = new TextView(thisView.getContext());
    textView.setText(thisView.getResources().getString(R.string.srl_component_falsify, getClass().getSimpleName(), DensityUtil.px2dp(thisView.getHeight())));
    textView.setTextColor(0xcccccccc);
    textView.setGravity(Gravity.CENTER);
    //noinspection UnnecessaryLocalVariable
    View view = textView;
    view.measure(makeMeasureSpec(thisView.getWidth(), EXACTLY), makeMeasureSpec(thisView.getHeight(), EXACTLY));
    view.layout(0, 0, thisView.getWidth(), thisView.getHeight());
    view.draw(canvas);
  }
}

代码示例来源:origin: stackoverflow.com

public class YourProject extends TabActivity {

  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources();
    TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1 title",
        res.getDrawable(R.drawable.logo1)).setContent(R.id.tab1Layout));

    (...)

    //You can also fill tabs with a separate activity like so:
    Intent intent = new Intent(this, YourClass.class);
    tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Another title",
        res.getDrawable(R.drawable.logo2)).setContent(intent));

    tabHost.setCurrentTab(0);
  }
}

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

private void checkForPollutionHelper() {
 assertThat(RuntimeEnvironment.getQualifiers())
   .isEqualTo("en-rUS-ldltr-sw320dp-w320dp-h470dp-normal-notlong-notround-" + optsForO + "port-notnight-mdpi-finger-keyssoft-nokeys-navhidden-nonav-v" + Build.VERSION.RESOURCES_SDK_INT);
 View view =
   LayoutInflater.from(ApplicationProvider.getApplicationContext())
     .inflate(R.layout.different_screen_sizes, null);
 TextView textView = view.findViewById(android.R.id.text1);
 assertThat(textView.getText().toString()).isEqualTo("default");
 RuntimeEnvironment.setQualifiers("fr-land"); // testing if this pollutes the other test
 Configuration configuration = Resources.getSystem().getConfiguration();
 if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.JELLY_BEAN) {
  configuration.locale = new Locale("fr", "FR");
 } else {
  configuration.setLocale(new Locale("fr", "FR"));
 }
 configuration.orientation = Configuration.ORIENTATION_LANDSCAPE;
 Resources.getSystem().updateConfiguration(configuration, null);
}

代码示例来源:origin: aa112901/remusic

@Override
  public void onClick(View v) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("http://music.baidu.com/songlist/" + playlsitId));
    shareIntent.setType("html/*");
    startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
  }
});

代码示例来源:origin: bluelinelabs/Conductor

@Override
protected void onViewBound(@NonNull View view) {
  super.onViewBound(view);
  if (displayUpMode != DisplayUpMode.SHOW) {
    view.findViewById(R.id.btn_up).setVisibility(View.GONE);
  }
  view.setBackgroundColor(ColorUtil.getMaterialColor(getResources(), index));
  tvTitle.setText(getResources().getString(R.string.navigation_title, index));
}

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

@Test @Config(qualifiers = "sw720dp")
public void inflateLayout_overridesTo_sw720dp() throws Exception {
 View view = Robolectric.setupActivity(Activity.class).getLayoutInflater().inflate(R.layout.layout_smallest_width, null);
 TextView textView = view.findViewById(R.id.text1);
 assertThat(textView.getText()).isEqualTo("720");
 assertThat(resources.getConfiguration().smallestScreenWidthDp).isEqualTo(720);
}

代码示例来源:origin: ZieIony/Carbon

public EditTextMenu(Context context) {
  super(LayoutInflater.from(context).inflate(R.layout.carbon_editormenu, null, false));
  getContentView().setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
  setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent)));
  setTouchable(true);
  setFocusable(true);
  setOutsideTouchable(true);
  setAnimationStyle(0);
  setClippingEnabled(false);
}

代码示例来源:origin: bluelinelabs/Conductor

@NonNull
@Override
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
  Log.i(TAG, "Conductor: onCreateView() called");
  View view = inflater.inflate(R.layout.controller_lifecycle, container, false);
  view.setBackgroundColor(ContextCompat.getColor(container.getContext(), R.color.orange_300));
  unbinder = ButterKnife.bind(this, view);
  tvTitle.setText(getResources().getString(R.string.rxlifecycle_title, TAG));
  return view;
}

代码示例来源:origin: north2016/T-MVP

private View getContainer(View rootView) {
  rootView.setBackgroundColor(getResources().getColor(R.color.alpha_white));
  View container = getLayoutInflater().inflate(R.layout.activity_base, null, false);
  SwipeBackLayout swipeBackLayout = (SwipeBackLayout) container.findViewById(R.id.swipeBackLayout);
  View ivShadow = container.findViewById(R.id.iv_shadow);
  swipeBackLayout.addView(rootView);
  swipeBackLayout.setOnScroll((fs) -> ivShadow.setAlpha(1 - fs));
  return container;
}

代码示例来源:origin: bluelinelabs/Conductor

@Override
protected void onViewBound(@NonNull View view) {
  super.onViewBound(view);
  tvTitle.setText(title);
  imgDot.getDrawable().setColorFilter(ContextCompat.getColor(getActivity(), dotColor), Mode.SRC_ATOP);
  ViewCompat.setTransitionName(tvTitle, getResources().getString(R.string.transition_tag_title_indexed, fromPosition));
  ViewCompat.setTransitionName(imgDot, getResources().getString(R.string.transition_tag_dot_indexed, fromPosition));
  recyclerView.setHasFixedSize(true);
  recyclerView.setLayoutManager(new GridLayoutManager(view.getContext(), 2));
  recyclerView.setAdapter(new CityGridAdapter(LayoutInflater.from(view.getContext()), CITY_MODELS));
}

代码示例来源:origin: bumptech/glide

private static int getResourceId(String type, String resourceName) {
  Context context = InstrumentationRegistry.getTargetContext();
  Resources res = context.getResources();
  return res.getIdentifier(resourceName, type, context.getPackageName());
 }
}

代码示例来源:origin: ankidroid/Anki-Android

ArrayList<String> names = getCol().getDecks().allNames();
int n = 1;
String name = String.format(Locale.getDefault(), "%s %d", res.getString(R.string.filtered_deck_name), n);
while (names.contains(name)) {
  n++;
  name = String.format(Locale.getDefault(), "%s %d", res.getString(R.string.filtered_deck_name), n);
    .title(res.getString(R.string.new_deck))
    .customView(mDialogEditText, true)
    .positiveText(res.getString(R.string.create))
    .negativeText(res.getString(R.string.dialog_cancel))
    .onPositive((dialog, which) -> {
      String filteredDeckName = mDialogEditText.getText().toString();
Intent noteTypeBrowser = new Intent(this, ModelBrowser.class);
startActivityForResultWithAnimation(noteTypeBrowser, 0, ActivityTransitionAnimation.LEFT);
return true;
String msg = getResources().getString(R.string.confirm_apkg_export);
showDialogFragment(ExportDialog.newInstance(msg));
return true;

代码示例来源:origin: stackoverflow.com

public class LocaleUtils {

  private static Locale sLocale;

  public static void setLocale(Locale locale) {
    sLocale = locale;
    if(sLocale != null) {
      Locale.setDefault(sLocale);
    }
  }

  public static void updateConfig(ContextThemeWrapper wrapper) {
    if(sLocale != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Configuration configuration = new Configuration();
      configuration.setLocale(sLocale);
      wrapper.applyOverrideConfiguration(configuration);
    }
  }

  public static void updateConfig(Application app, Configuration configuration) {
    if(sLocale != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
      //Wrapping the configuration to avoid Activity endless loop
      Configuration config = new Configuration(configuration);
      config.locale = sLocale;
      Resources res = app.getBaseContext().getResources();
      res.updateConfiguration(config, res.getDisplayMetrics());
    }
  }
}

相关文章

微信公众号

最新文章

更多