android.app.Activity.getResources()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(451)

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

Activity.getResources介绍

暂无

代码示例

代码示例来源:origin: TommyLemon/APIJSON

public final Resources getResources() {
  if(resources == null) {
    resources = context.getResources();
  } 
  return resources;
}

代码示例来源:origin: Justson/AgentWeb

@Override
  protected void bindSupportWebParent(WebParentLayout webParentLayout, Activity activity) {
    this.mActivity = activity;
    this.mWebParentLayout = webParentLayout;
    mResources = this.mActivity.getResources();

  }
}

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

final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
  Bitmap image = BlurBuilder.blur(content);
  window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image));
} else {
  content.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      Bitmap image = BlurBuilder.blur(content);
      window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image));
    }
  });
}

代码示例来源:origin: mikepenz/MaterialDrawer

/**
 * Set the DrawerBuilder width with a dimension resource
 *
 * @param drawerWidthRes
 * @return
 */
public DrawerBuilder withDrawerWidthRes(@DimenRes int drawerWidthRes) {
  if (mActivity == null) {
    throw new RuntimeException("please pass an activity first to use this call");
  }
  this.mDrawerWidth = mActivity.getResources().getDimensionPixelSize(drawerWidthRes);
  return this;
}

代码示例来源:origin: naman14/Timber

private void clearExtraSpacingBetweenCards(RecyclerView albumsRecyclerview) {
  //to clear any extra spacing between cards
  int spacingInPixelstoClear = -(mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card));
  albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixelstoClear));
}

代码示例来源:origin: facebook/facebook-android-sdk

public LocationListElement(int requestCode) {
  super(getActivity().getResources().getDrawable(R.drawable.add_location),
      getActivity().getResources().getString(R.string.action_location),
      null,
      requestCode);
}

代码示例来源:origin: TommyLemon/APIJSON

/**展示加载进度条,无标题
 * @param stringResId
 */
public static void showProgressDialog(Activity context, int stringResId){
  try {
    showProgressDialog(context, null, context.getResources().getString(stringResId));
  } catch (Exception e) {
    Log.e(TAG, "showProgressDialog  showProgressDialog(Context context, null, context.getResources().getString(stringResId));");
  }
}
/**展示加载进度条,无标题

代码示例来源:origin: facebook/facebook-android-sdk

public PeopleListElement(int requestCode) {
  super(getActivity().getResources().getDrawable(R.drawable.add_friends),
      getActivity().getResources().getString(R.string.action_people),
      null,
      requestCode);
}

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

/**
 * 获取ActionBar高度
 *
 * @param activity activity
 * @return ActionBar高度
 */
public static int getActionBarHeight(Activity activity) {
  TypedValue tv = new TypedValue();
  if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
    return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
  }
  return 0;
}

代码示例来源:origin: naman14/Timber

private void setUpAlbums(RecyclerView albumsRecyclerview) {
  albumsRecyclerview.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
  albumsRecyclerview.setHasFixedSize(true);
  //to add spacing between cards
  int spacingInPixels = mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card);
  albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
  albumsRecyclerview.setNestedScrollingEnabled(false);
  ArtistAlbumAdapter mAlbumAdapter = new ArtistAlbumAdapter(mContext, ArtistAlbumLoader.getAlbumsForArtist(mContext, artistID));
  albumsRecyclerview.setAdapter(mAlbumAdapter);
}

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

@Override
public void onStart() {
  super.onStart();
  //设置fragment高度 、宽度
  int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.65);
  int dialogWidth = (int) (mContext.getResources().getDisplayMetrics().widthPixels * 0.77);
  getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
  getDialog().setCanceledOnTouchOutside(true);
}

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

@Override
public void onStart() {
  super.onStart();
  //设置fragment高度 、宽度
  int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.71);
  int dialogWidth = (int) (mContext.getResources().getDisplayMetrics().widthPixels * 0.79);
  getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
  getDialog().setCanceledOnTouchOutside(true);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  int res=
    getActivity().getResources()
           .getIdentifier(getArguments().getString("resource"),
                  "xml",
                  getActivity().getPackageName());

  addPreferencesFromResource(res);
 }
}

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

@Override
public void onStart() {
  super.onStart();
  //设置fragment高度 、宽度
  int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.30);
  getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, dialogHeight);
  getDialog().setCanceledOnTouchOutside(true);
}

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

@Override
  public void onStart() {
    super.onStart();
    //设置fragment高度 、宽度
    int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * heightPercent);
    ;
//        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
//        Display display = wm.getDefaultDisplay();
//        int height = display.getHeight();
    getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, dialogHeight);
    getDialog().setCanceledOnTouchOutside(true);

  }

代码示例来源:origin: TommyLemon/APIJSON

private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) {
  Resources res = activity.getResources();
  mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
  mSmallestWidthDp = getSmallestWidthDp(activity);
  mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME);
  mActionBarHeight = getActionBarHeight(activity);
  mNavigationBarHeight = getNavigationBarHeight(activity);
  mNavigationBarWidth = getNavigationBarWidth(activity);
  mHasNavigationBar = (mNavigationBarHeight > 0);
  mTranslucentStatusBar = translucentStatusBar;
  mTranslucentNavBar = traslucentNavBar;
}

代码示例来源:origin: commonsguy/cw-omnibus

ForecastAdapter(List<WeatherResponse.Period> items) {
 super(getActivity(), R.layout.row, R.id.date, items);
 size=getActivity()
  .getResources()
  .getDimensionPixelSize(R.dimen.icon);
 dateFormat=DateFormat.getDateFormat(getActivity());
 timeFormat=DateFormat.getTimeFormat(getActivity());
}

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

@Test
public void shouldSetTextAndTextColorWhileInflatingXmlLayout() throws Exception {
 Activity activity = activityController.get();
 activity.setContentView(R.layout.text_views);
 TextView black = (TextView) activity.findViewById(R.id.black_text_view);
 assertThat(black.getText().toString()).isEqualTo("Black Text");
 assertThat(black.getCurrentTextColor()).isEqualTo(0xff000000);
 TextView white = (TextView) activity.findViewById(R.id.white_text_view);
 assertThat(white.getText().toString()).isEqualTo("White Text");
 assertThat(white.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white));
 TextView grey = (TextView) activity.findViewById(R.id.grey_text_view);
 assertThat(grey.getText().toString()).isEqualTo("Grey Text");
 assertThat(grey.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42));
}

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

@Test
 public void getBackgroundDrawable() throws Exception {
  Drawable drawable = activity.getResources().getDrawable(android.R.drawable.bottom_bar);
  window.setBackgroundDrawable(drawable);
  assertThat(shadowOf(window).getBackgroundDrawable()).isSameAs(drawable);
 }
}

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

@Test
public void shouldSetHintAndHintColorWhileInflatingXmlLayout() throws Exception {
 Activity activity = activityController.get();
 activity.setContentView(R.layout.text_views_hints);
 TextView black = (TextView) activity.findViewById(R.id.black_text_view_hint);
 assertThat(black.getHint().toString()).isEqualTo("Black Hint");
 assertThat(black.getCurrentHintTextColor()).isEqualTo(0xff000000);
 TextView white = (TextView) activity.findViewById(R.id.white_text_view_hint);
 assertThat(white.getHint().toString()).isEqualTo("White Hint");
 assertThat(white.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white));
 TextView grey = (TextView) activity.findViewById(R.id.grey_text_view_hint);
 assertThat(grey.getHint().toString()).isEqualTo("Grey Hint");
 assertThat(grey.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42));
}

相关文章

Activity类方法