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

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

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

Activity.setContentView介绍

暂无

代码示例

代码示例来源:origin: GitLqr/LQRWeChat

public void onCreate() {
  activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000));
  sivViewer = new ScaledImageView(activity);
  sivViewer.setScaleType(ScaleType.MATRIX);
  activity.setContentView(sivViewer);
  if (pic != null) {
    sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this);
  }
}

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

public void onCreate() {
  activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000));
  sivViewer = new ScaledImageView(activity);
  sivViewer.setScaleType(ScaleType.MATRIX);
  activity.setContentView(sivViewer);
  if (pic != null) {
    sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this);
  }
}

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

@Override
public DefaultWebCreator create() {
  if (mIsCreated) {
    return this;
  }
  mIsCreated = true;
  ViewGroup mViewGroup = this.mViewGroup;
  if (mViewGroup == null) {
    mViewGroup = this.mFrameLayout = (FrameLayout) createLayout();
    mActivity.setContentView(mViewGroup);
  } else {
    if (mIndex == -1) {
      mViewGroup.addView(this.mFrameLayout = (FrameLayout) createLayout(), mLayoutParams);
    } else {
      mViewGroup.addView(this.mFrameLayout = (FrameLayout) createLayout(), mIndex, mLayoutParams);
    }
  }
  return this;
}

代码示例来源:origin: GitLqr/LQRWeChat

public void onCreate() {
  super.onCreate();
  int screenHeight = ResHelper.getScreenHeight(activity);
  float ratio = ((float) screenHeight) / DESIGN_SCREEN_HEIGHT;
  maxBodyHeight = 0;
  llPage = new LinearLayout(activity);
  llPage.setOrientation(LinearLayout.VERTICAL);
  activity.setContentView(llPage);
  rlTitle = new RelativeLayout(activity);
  rlTitle.setBackgroundColor(0xffe6e9ec);
  int titleHeight = (int) (DESIGN_TITLE_HEIGHT * ratio);
  LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight);
  llPage.addView(rlTitle, lp);
  initTitle(rlTitle, ratio);
  RelativeLayout rlBody = new RelativeLayout(activity);
  rlBody.setBackgroundColor(0xffffffff);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(rlBody, lp);
  initBody(rlBody, ratio);
  LinearLayout llShadow = new LinearLayout(activity);
  llShadow.setOrientation(LinearLayout.VERTICAL);
  rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  initShadow(llShadow, ratio);
  llBottom = new LinearLayout(activity);
  llBottom.setOrientation(LinearLayout.VERTICAL);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(llBottom, lp);
  initBottom(llBottom, ratio);
}

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

public void onCreate() {
  super.onCreate();
  int screenHeight = R.getScreenHeight(activity);
  float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH;
  maxBodyHeight = 0;
  llPage = new LinearLayout(activity);
  llPage.setOrientation(LinearLayout.VERTICAL);
  activity.setContentView(llPage);
  rlTitle = new RelativeLayout(activity);
  rlTitle.setBackgroundColor(0xffe6e9ec);
  int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio);
  LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight);
  llPage.addView(rlTitle, lp);
  initTitle(rlTitle, ratio);
  RelativeLayout rlBody = new RelativeLayout(activity);
  rlBody.setBackgroundColor(0xffffffff);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(rlBody, lp);
  initBody(rlBody, ratio);
  LinearLayout llShadow = new LinearLayout(activity);
  llShadow.setOrientation(LinearLayout.VERTICAL);
  rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  initShadow(llShadow, ratio);
  llBottom = new LinearLayout(activity);
  llBottom.setOrientation(LinearLayout.VERTICAL);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(llBottom, lp);
  initBottom(llBottom, ratio);
}

代码示例来源:origin: GitLqr/LQRWeChat

public void onCreate() {
  super.onCreate();
  int screenHeight = ResHelper.getScreenHeight(activity);
  float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH;
  maxBodyHeight = 0;
  llPage = new LinearLayout(activity);
  llPage.setOrientation(LinearLayout.VERTICAL);
  activity.setContentView(llPage);
  rlTitle = new RelativeLayout(activity);
  rlTitle.setBackgroundColor(0xffe6e9ec);
  int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio);
  LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight);
  llPage.addView(rlTitle, lp);
  initTitle(rlTitle, ratio);
  RelativeLayout rlBody = new RelativeLayout(activity);
  rlBody.setBackgroundColor(0xffffffff);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(rlBody, lp);
  initBody(rlBody, ratio);
  LinearLayout llShadow = new LinearLayout(activity);
  llShadow.setOrientation(LinearLayout.VERTICAL);
  rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  initShadow(llShadow, ratio);
  llBottom = new LinearLayout(activity);
  llBottom.setOrientation(LinearLayout.VERTICAL);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(llBottom, lp);
  initBottom(llBottom, ratio);
}

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

public void onCreate() {
  super.onCreate();
  int screenHeight = R.getScreenHeight(activity);
  float ratio = ((float) screenHeight) / DESIGN_SCREEN_HEIGHT;
  maxBodyHeight = 0;
  llPage = new LinearLayout(activity);
  llPage.setOrientation(LinearLayout.VERTICAL);
  activity.setContentView(llPage);
  rlTitle = new RelativeLayout(activity);
  rlTitle.setBackgroundColor(0xffe6e9ec);
  int titleHeight = (int) (DESIGN_TITLE_HEIGHT * ratio);
  LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight);
  llPage.addView(rlTitle, lp);
  initTitle(rlTitle, ratio);
  RelativeLayout rlBody = new RelativeLayout(activity);
  rlBody.setBackgroundColor(0xffffffff);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(rlBody, lp);
  initBody(rlBody, ratio);
  LinearLayout llShadow = new LinearLayout(activity);
  llShadow.setOrientation(LinearLayout.VERTICAL);
  rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
  initShadow(llShadow, ratio);
  llBottom = new LinearLayout(activity);
  llBottom.setOrientation(LinearLayout.VERTICAL);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  llPage.addView(llBottom, lp);
  initBottom(llBottom, ratio);
}

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

@Before
public void setUp() {
 activity = Robolectric.setupActivity(Activity.class);
 view = new View(activity);
 activity.setContentView(view);
 listener = new TestListener();
}

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

@Test public void setContentView_shouldReplaceOldContentView() throws Exception {
 View view1 = new View(application);
 view1.setId(R.id.burritos);
 View view2 = new View(application);
 view2.setId(R.id.button);
 Activity activity = buildActivity(Activity.class).create().get();
 activity.setContentView(view1);
 assertSame(view1, activity.findViewById(R.id.burritos));
 activity.setContentView(view2);
 assertNull(activity.findViewById(R.id.burritos));
 assertSame(view2, activity.findViewById(R.id.button));
}

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

@Test // unclear what the correct behavior should be here...
public void shouldPopulateWindowDecorViewWithMergeLayoutContents() throws Exception {
 Activity activity = Robolectric.buildActivity(Activity.class).create().get();
 activity.setContentView(R.layout.toplevel_merge);
 View contentView = activity.findViewById(android.R.id.content);
 assertThat(((ViewGroup) contentView).getChildCount()).isEqualTo(2);
}

代码示例来源: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));
}

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

@Test
@Config(qualifiers = "w0dp")
public void testSetContentViewByItemResource() throws Exception {
 Activity activity = buildActivity(Activity.class).create().get();
 activity.setContentView(R.layout.main_layout);
 TextView tv1 = activity.findViewById(R.id.hello);
 TextView tv2 = activity.findViewById(R.id.world);
 assertNotNull(tv1);
 assertNull(tv2);
}

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

@Test
@Config(qualifiers = "w820dp")
public void testSetContentViewByItemResourceWithW820dp() throws Exception {
 Activity activity = buildActivity(Activity.class).create().get();
 activity.setContentView(R.layout.main_layout);
 TextView tv1 = activity.findViewById(R.id.hello);
 TextView tv2 = activity.findViewById(R.id.world);
 assertNotNull(tv1);
 assertNotNull(tv2);
}

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

@Test
public void shouldFindContentViewContainerWithChild() throws Exception {
 Activity activity = buildActivity(Activity.class).create().get();
 View contentView = new View(activity);
 activity.setContentView(contentView);
 FrameLayout contentViewContainer = (FrameLayout) activity.findViewById(android.R.id.content);
 assertThat(contentViewContainer.getChildAt(0)).isSameAs(contentView);
}

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

@Test
public void usesDefaultGlobalVisibleRect() {
 final ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class);
 final Activity activity = activityController.get();
 activity.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
     ViewGroup.LayoutParams.MATCH_PARENT));
 activityController.setup();
 Rect globalVisibleRect = new Rect();
 assertThat(view.getGlobalVisibleRect(globalVisibleRect))
   .isTrue();
 assertThat(globalVisibleRect)
   .isEqualTo(new Rect(0, 25,
     DeviceConfig.DEFAULT_SCREEN_SIZE.width, DeviceConfig.DEFAULT_SCREEN_SIZE.height));
}

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

@Before
public void setUp() {
 sdkVersion = Build.VERSION.SDK_INT;
 MockitoAnnotations.initMocks(this);
 activity = Robolectric.buildActivity(Activity.class).create().start().postCreate(null).resume();
 view = new View(activity.get());
 target = new TestViewTarget(view);
 attachStateTarget = new AttachStateTarget(view);
 LinearLayout linearLayout = new LinearLayout(activity.get());
 View expandView = new View(activity.get());
 LinearLayout.LayoutParams linearLayoutParams =
   new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, /*height=*/ 0);
 linearLayoutParams.weight = 1f;
 expandView.setLayoutParams(linearLayoutParams);
 linearLayout.addView(expandView);
 parent = new FrameLayout(activity.get());
 parent.addView(view);
 linearLayout.addView(parent);
 activity.get().setContentView(linearLayout);
}

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

@Test
public void testInvalidOnClickAttribute() throws Exception {
 Activity activity = buildActivity(Activity.class).create().get();
 activity.setContentView(R.layout.with_invalid_onclick);
 Button button = activity.findViewById(R.id.invalid_onclick_button);
 IllegalStateException exception = null;
 try {
  button.performClick();
 } catch (IllegalStateException e) {
  exception = e;
 }
 assertNotNull(exception);
 assertThat(exception.getMessage())
   .named("The error message should contain the id name of the faulty button")
   .contains("invalid_onclick_button");
}

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

@Test
public void shouldRetrieveTheCurrentViewFromViewId() {
 Activity activity = Robolectric.buildActivity(Activity.class).create().get();
 activity.setContentView(org.robolectric.R.layout.main);
 TabHost tabHost = new TabHost(activity);
 TabHost.TabSpec foo = tabHost.newTabSpec("Foo")
 .setContent(org.robolectric.R.id.title);
  tabHost.addTab(foo);
  tabHost.setCurrentTabByTag("Foo");
  TextView textView = (TextView) tabHost.getCurrentView();
 assertThat(textView.getText().toString()).isEqualTo("Main Layout");
}

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

@Before
public void setUp() throws Exception {
 activityController = buildActivity(Activity.class);
 Activity activity = activityController.create().get();
 textView = new TextView(activity);
 activity.setContentView(textView);
 activityController.start().resume().visible();
}

相关文章

微信公众号

最新文章

更多

Activity类方法