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

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

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

Activity.getTheme介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

/**
 * Get the background color of the theme used for this activity.
 *
 * @return The background color of the current theme.
 */
public int getThemeBackgroundColor() {
  TypedArray array = mActivity.getTheme().obtainStyledAttributes(
      new int[] { android.R.attr.colorBackground });
  int backgroundColor = array.getColor(0, 0xFF00FF);
  array.recycle();
  return backgroundColor;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 获取某个属性的TypedValue
 * @param ctx 上下文
 * @param attr  属性id
 * @return
 */
public static TypedValue getAttrTypedValue(Activity ctx,int attr){
  TypedValue typedValue = new TypedValue();
  Resources.Theme theme = ctx.getTheme();
  theme.resolveAttribute(attr, typedValue, true);
  return typedValue;
}

代码示例来源:origin: bingoogolapple/BGASwipeBackLayout-Android

BGASwipeBackShadowView(Activity activity) {
  super(activity);
  mActivity = activity;
  TypedArray typedArray = mActivity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowIsTranslucent
  });
  mIsCurrentActivityTranslucent = typedArray.getBoolean(0, false);
  typedArray.recycle();
}

代码示例来源: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: jaydenxiao2016/AndroidFire

/**
 * 刷新 StatusBar
 * @param ctx  上下文
 */
private static void refreshStatusBar(Activity ctx) {
  if (Build.VERSION.SDK_INT >= 21) {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = ctx.getTheme();
    theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    ctx.getWindow().setStatusBarColor(ctx.getResources().getColor(typedValue.resourceId));
  }
}
/**

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

public void attachToActivity(Activity activity) {
  mActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowBackground
  });
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  setContentView(decorChild);
  decor.addView(this);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 刷新UI界面
 * @param ctx  上下文
 */
private static void refreshUI(Activity ctx) {
  TypedValue typedValue = new TypedValue();
  Resources.Theme theme = ctx.getTheme();
  theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
  View view = ctx.findViewById(R.id.action_bar);
  if(view!=null){
    view.setBackgroundResource(typedValue.resourceId);
  }
  for(AttrEntity<View> entity:mBackGroundViews){
    theme.resolveAttribute(entity.colorId, typedValue, true);
    entity.v.setBackgroundResource(typedValue.resourceId);
  }
  for(AttrEntity<View> entity:mBackGroundDrawableViews){
    theme.resolveAttribute(entity.colorId, typedValue, true);
    entity.v.setBackgroundResource(typedValue.resourceId);
  }
  for (AttrEntity<TextView> entity: mOneTextColorViews){
    theme.resolveAttribute(entity.colorId, typedValue, true);
    entity.v.setTextColor(ctx.getResources().getColor(typedValue.resourceId));
  }
  for (AttrEntity<TextView> entity: mOneTextColorViews){
    theme.resolveAttribute(entity.colorId, typedValue, true);
    entity.v.setTextColor(ctx.getResources().getColor(typedValue.resourceId));
  }
  //refreshStatusBar(ctx);
}

代码示例来源:origin: joyoyao/superCleanMaster

public void attachToActivity(Activity activity) {
  mActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowBackground
  });
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  setContentView(decorChild);
  decor.addView(this);
}

代码示例来源:origin: wangdan/AisenWeiBo

public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
        android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    // 这里可以设置背景颜色
    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
//        decorChild.setBackgroundColor(Color.parseColor("#fffafafa"));
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
  }

代码示例来源:origin: Rukey7/MvpApp

/**
 * 设置关联的 Activity
 * 重要!必须调用
 *
 * @param activity
 */
public void attachToActivity(Activity activity, @EdgeFlag int edgeFlag) {
  mAttachActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowBackground
  });
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  _setContentView(decorChild);
  decor.addView(this);
  setEdgeFlag(edgeFlag);
}

代码示例来源:origin: hidroh/materialistic

@Test
public void testDefaultTextSize() {
  Activity activity = Robolectric.setupActivity(Activity.class);
  float expected = activity.getTheme().obtainStyledAttributes(R.style.AppTextSize,
      new int[]{R.attr.contentTextSize}).getDimension(0, 0);
  float actual = activity.getTheme().obtainStyledAttributes(
      new int[]{R.attr.contentTextSize}).getDimension(0, 0);
  assertThat(actual).isEqualTo(expected);
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

@NonNull
@Override
public Resources.Theme getTheme()
{
  return mActivity.getTheme();
}

代码示例来源:origin: GeekGhost/Ghost

public void attachToActivity(Activity activity) {
  mActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(
      new int[]{android.R.attr.windowBackground});
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  setContentView(decorChild);
  decor.addView(this);
}

代码示例来源:origin: liuling07/SimpleNews

public void attachToActivity(Activity activity) {
  mActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowBackground
  });
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  setContentView(decorChild);
  decor.addView(this);
}

代码示例来源:origin: tianshaojie/AndroidFine

public void attachToActivity(Activity activity) {
  mActivity = activity;
  TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
      android.R.attr.windowBackground
  });
  int background = a.getResourceId(0, 0);
  a.recycle();
  ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
  // ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
  decorChild.setBackgroundResource(background);
  decor.removeView(decorChild);
  addView(decorChild);
  setContentView(decorChild);
  decor.addView(this);
}

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

final Theme theme = activity.getTheme();
final TypedArray ta = theme
  .obtainStyledAttributes(new int[] { android.R.attr.windowBackground });

代码示例来源:origin: typ0520/fastdex

Resources.Theme theme = activity.getTheme();
try {
  try {

代码示例来源:origin: chaychan/TouTiao

static void setStatusBarColor(Activity activity, int statusColor) {
  Window window = activity.getWindow();
  //设置Window为全透明
  window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
  //获取父布局
  View mContentChild = mContentView.getChildAt(0);
  //获取状态栏高度
  int statusBarHeight = getStatusBarHeight(activity);
  //如果已经存在假状态栏则移除,防止重复添加
  removeFakeStatusBarViewIfExist(activity);
  //添加一个View来作为状态栏的填充
  addFakeStatusBarView(activity, statusColor, statusBarHeight);
  //设置子控件到状态栏的间距
  addMarginTopToContentChild(mContentChild, statusBarHeight);
  //不预留系统栏位置
  if (mContentChild != null) {
    ViewCompat.setFitsSystemWindows(mContentChild, false);
  }
  //如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡
  int action_bar_id = activity.getResources().getIdentifier("action_bar", "id", activity.getPackageName());
  View view = activity.findViewById(action_bar_id);
  if (view != null) {
    TypedValue typedValue = new TypedValue();
    if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
      int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics());
      Eyes.setContentTopPadding(activity, actionBarHeight);
    }
  }
}

代码示例来源:origin: iReaderAndroid/ZeusPlugin

/**
 * 给ZeusHelper调用的获取原始theme的方法
 * @return
 */
public Resources.Theme getSuperTheme() {
  return super.getTheme();
}
//---------------------------插件相关代码-------------------------end

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

public static int getResIdFromAttribute(final Activity activity,final int attr)
 {
 if(attr==0)
  return 0;
 final TypedValue typedvalueattr=new TypedValue();
 activity.getTheme().resolveAttribute(attr,typedvalueattr,true);
 return typedvalueattr.resourceId;
 }

相关文章

微信公众号

最新文章

更多

Activity类方法