本文整理了Java中android.app.Activity
类的一些代码示例,展示了Activity
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity
类的具体详情如下:
包路径:android.app.Activity
类名称:Activity
暂无
代码示例来源:origin: googlesamples/android-testing
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_text);
// Get the message from the Intent.
Intent intent = getIntent();
String message = Strings.nullToEmpty(intent.getStringExtra(KEY_EXTRA_MESSAGE));
// Show message.
((TextView)findViewById(R.id.show_text_view)).setText(message);
}
代码示例来源:origin: stackoverflow.com
Activity activity = ...;
AlertDialog dialog = ...;
// retrieve display dimensions
Rect displayRectangle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
// inflate and adjust layout
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.your_dialog_layout, null);
layout.setMinimumWidth((int)(displayRectangle.width() * 0.9f));
layout.setMinimumHeight((int)(displayRectangle.height() * 0.9f));
dialog.setView(layout);
代码示例来源:origin: TommyLemon/APIJSON
@Override
public void finish() {
setResult(RESULT_OK, new Intent()
.putExtra(RESULT_ID, id)
.putExtra(RESULT_URL, url)
.putExtra(RESULT_METHOD, method)
.putExtra(RESULT_NAME, name)
.putExtra(RESULT_RESPONSE, resultJson)
);
super.finish();
}
代码示例来源:origin: square/picasso
public void launch(Activity activity) {
activity.startActivity(new Intent(activity, activityClass));
activity.finish();
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void navigateUpTo(Activity activity, Intent upIntent) {
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(upIntent);
activity.finish();
}
代码示例来源:origin: bumptech/glide
@Override
public void onClick(View view) {
ClipboardManager clipboard =
(ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip =
ClipData.newPlainText("giphy_url", result.images.fixed_height.url);
Preconditions.checkNotNull(clipboard).setPrimaryClip(clip);
Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result);
activity.startActivity(fullscreenIntent);
}
});
代码示例来源:origin: nuptboyzhb/SuperSwipeRefreshLayout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrollview);
swipeRefreshLayout = (SuperSwipeRefreshLayout) findViewById(R.id.swipe_refresh);
View child = LayoutInflater.from(swipeRefreshLayout.getContext())
.inflate(R.layout.layout_head, null);
progressBar = (ProgressBar) child.findViewById(R.id.pb_view);
textView = (TextView) child.findViewById(R.id.text_view);
textView.setText("下拉刷新");
imageView = (ImageView) child.findViewById(R.id.image_view);
imageView.setVisibility(View.VISIBLE);
imageView.setImageResource(R.drawable.down_arrow);
progressBar.setVisibility(View.GONE);
swipeRefreshLayout.setHeaderView(child);
代码示例来源:origin: ukanth/afwall
if (convertView == null) {
convertView = inflater.inflate(R.layout.main_list, parent, false);
holder = new AppStateHolder();
holder.box_wifi = (CheckBox) convertView.findViewById(R.id.itemcheck_wifi);
holder.text = (TextView) convertView.findViewById(R.id.itemtext);
holder.icon = (ImageView) convertView.findViewById(R.id.itemicon);
holder.icon.setVisibility(View.GONE);
activity.findViewById(R.id.imageHolder).setVisibility(View.GONE);
convertView.setTag(holder);
holder.icon = (ImageView) convertView.findViewById(R.id.itemicon);
if (G.disableIcons()) {
holder.icon.setVisibility(View.GONE);
activity.findViewById(R.id.imageHolder).setVisibility(View.GONE);
holder.text.setText(holder.app.toStringWithUID());
} else {
holder.text.setText(holder.app.toString());
holder.icon.setVisibility(View.GONE);
activity.findViewById(R.id.imageHolder).setVisibility(View.GONE);
代码示例来源:origin: osmandapp/Osmand
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
descriptionTextView.setText(Html.fromHtml(getString(R.string.plugin_description)));
Intent intentPlus = new Intent();
intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY));
intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY);
if(resolved != null) {
} else {
logEvent(this, "open_dialog");
findViewById(R.id.buyButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
代码示例来源:origin: ksoichiro/Android-ObservableScrollView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_scrollview_noheader, container, false);
final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
Activity parentActivity = getActivity();
scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));
if (parentActivity instanceof ObservableScrollViewCallbacks) {
scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
}
代码示例来源:origin: vekexasia/android-edittext-validator
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_examplegeneric);
flContainer = (FrameLayout) findViewById(R.id.fl);
tvExplanation = (TextView) findViewById(R.id.tv_explanation);
tvTitle = (TextView) findViewById(R.id.tv_title);
flContainer.addView(LayoutInflater.from(this).inflate(getIntent().getIntExtra(EXTRA_LAYOUT_RES, 0), flContainer, false));
tvExplanation.setText(getIntent().getIntExtra(EXTRA_LAYOUT_EXPL_STR_RES, 0));
tvTitle.setText(getIntent().getStringExtra(EXTRA_TITLE));
}
代码示例来源:origin: jjhesk/KickAssSlidingMenu
@SuppressLint("ResourceAsColor")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(this);
setContentView(inflater.inflate(R.layout.horz_scroll_with_image_menu, null));
app = inflater.inflate(R.layout.horz_scroll_app, null);
ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);
ListView listView = (ListView) app.findViewById(R.id.list);
ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
btnSlide.setOnClickListener(new HorzScrollWithListMenu.ClickListenerForScrolling(scrollView, menu));
View transparent = new TextView(this);
transparent.setBackgroundColor(android.R.color.transparent);
代码示例来源:origin: stackoverflow.com
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) activity.findViewById(R.id.toast_root));
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
image.setImageResource(R.drawable.skipper_toast);
TextView text_toast = (TextView) layout.findViewById(R.id.toast_text);
text_toast.setText(text);
代码示例来源:origin: vekexasia/android-edittext-validator
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_examplegeneric);
flContainer = (FrameLayout) findViewById(R.id.fl);
tvExplanation = (TextView) findViewById(R.id.tv_explanation);
tvTitle = (TextView) findViewById(R.id.tv_title);
flContainer.addView(LayoutInflater.from(this).inflate(R.layout.example_email_or_creditcard, flContainer, false));
tvExplanation.setText(R.string.explanation_emailorcredit);
tvTitle.setText(R.string.emailorcredit_title);
//Interesting stuff starts here
FormEditText fdt = (FormEditText) findViewById(R.id.et);
fdt.addValidator(
new OrValidator(
"This is neither a creditcard or an email",
new CreditCardValidator(null), // we specify null as the message string cause the Or validator will use his own message
new EmailValidator(null) // same here for null
)
);
}
代码示例来源:origin: stackoverflow.com
try {
LayoutInflater inflater = callingActivity.getLayoutInflater();
dlg = inflater.inflate(R.layout.alertmono, (ViewGroup) callingActivity.findViewById(R.id.dlgView));
tvText = (TextView) dlg.findViewById(R.id.dlgText);
} catch(InflateException e) {
tvText.setText( "22-05-2012 20:51:13 114 58 00:04:19\n"+
"22-05-2012 20:59:15 84 52 00:01:25\n"+
"22-05-2012 22:49:48 96 51 00:01:32\n"+
.setTitle(callingActivity.getString(R.string.app_name))
.setCancelable(true)
.setIcon(R.drawable.ic_launcher)
代码示例来源:origin: ksoichiro/Android-ObservableScrollView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_touchinterception_webview);
((TextView) findViewById(R.id.title)).setText(getClass().getSimpleName());
mScrollable = (Scrollable) findViewById(R.id.scrollable);
mScrollable.setScrollViewCallbacks(this);
((WebView) mScrollable).loadUrl("file:///android_asset/lipsum.html");
mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height);
mHeaderBarHeight = getResources().getDimensionPixelSize(R.dimen.header_bar_height);
mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.scroll_wrapper);
mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
}
代码示例来源:origin: alexjlockwood/adp-activity-transitions
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_details, container, false);
mAlbumImage = (ImageView) rootView.findViewById(R.id.details_album_image);
final ImageView backgroundImage = (ImageView) rootView.findViewById(R.id.details_background_image);
View textContainer = rootView.findViewById(R.id.details_text_container);
TextView albumTitleText = (TextView) textContainer.findViewById(R.id.details_album_title);
String albumImageUrl = ALBUM_IMAGE_URLS[mAlbumPosition];
String backgroundImageUrl = BACKGROUND_IMAGE_URLS[mAlbumPosition];
String albumName = ALBUM_NAMES[mAlbumPosition];
albumTitleText.setText(albumName);
mAlbumImage.setTransitionName(albumName);
RequestCreator albumImageRequest = Picasso.with(getActivity()).load(albumImageUrl);
RequestCreator backgroundImageRequest = Picasso.with(getActivity()).load(backgroundImageUrl).fit().centerCrop();
if (mIsTransitioning) {
albumImageRequest.noFade();
backgroundImageRequest.noFade();
backgroundImage.setAlpha(0f);
getActivity().getWindow().getSharedElementEnterTransition().addListener(new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
backgroundImage.animate().setDuration(mBackgroundImageFadeMillis).alpha(1f);
}
});
}
albumImageRequest.into(mAlbumImage, mImageCallback);
backgroundImageRequest.into(backgroundImage);
return rootView;
}
代码示例来源:origin: jjhesk/KickAssSlidingMenu
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
setContentView(scrollView);
menu = inflater.inflate(R.layout.horz_scroll_menu, null);
app = inflater.inflate(R.layout.horz_scroll_app, null);
ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);
ListView listView = (ListView) app.findViewById(R.id.list);
ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
listView = (ListView) menu.findViewById(R.id.list);
ViewUtils.initListView(this, listView, "Menu ", 30, android.R.layout.simple_list_item_1);
btnSlide = (ImageView) tabBar.findViewById(R.id.BtnSlide);
btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu));
final View[] children = new View[] { menu, app };
// Scroll to app (view[1]) when layout finished.
int scrollToViewIdx = 1;
scrollView.initViews(children, scrollToViewIdx, new SizeCallbackForMenu(btnSlide));
}
代码示例来源:origin: stackoverflow.com
public class CustomToast {
public static Toast makeToast(Activity activity, String text, int duraion ){
LayoutInflater inflater = activity.getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_achievement, (ViewGroup) activity.findViewById(R.id.toast_layout_root));
TextView textView = (TextView) layout.findViewById(R.id.text);
textView.setText(text);
Toast toast = new Toast(activity.getApplicationContext());
toast.setDuration(duraion);
toast.setView(layout);
toast.setGravity(Gravity.CENTER, 0, 0);
return toast;
}
}
代码示例来源:origin: jjdxmashl/jjdxm_ijkplayer
if (rootView == null) {
query = new LayoutQuery(mActivity);
rl_box = mActivity.findViewById(R.id.app_video_box);
videoView = (IjkVideoView) mActivity.findViewById(R.id.video_view);
settingsContainer = mActivity.findViewById(R.id.simple_player_settings_container);
settingsContainer.setVisibility(View.GONE);
volumeControllerContainer = mActivity.findViewById(R.id.simple_player_volume_controller_container);
volumeController = (SeekBar) mActivity.findViewById(R.id.simple_player_volume_controller);
volumeController.setMax(100);
volumeController.setOnSeekBarChangeListener(this.onVolumeControllerChangeListener);
brightnessControllerContainer = mActivity.findViewById(R.id.simple_player_brightness_controller_container);
brightnessController = (SeekBar) mActivity.findViewById(R.id.simple_player_brightness_controller);
brightnessController.setMax(100);
} else {
query = new LayoutQuery(mActivity, rootView);
rl_box = rootView.findViewById(R.id.app_video_box);
videoView = (IjkVideoView) rootView.findViewById(R.id.video_view);
int e = Settings.System.getInt(this.mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
float progress = 1.0F * (float) e / 255.0F;
android.view.WindowManager.LayoutParams layout = this.mActivity.getWindow().getAttributes();
layout.screenBrightness = progress;
mActivity.getWindow().setAttributes(layout);
} catch (Settings.SettingNotFoundException var7) {
var7.printStackTrace();
streamSelectView = (LinearLayout) mActivity.findViewById(R.id.simple_player_select_stream_container);
内容来源于网络,如有侵权,请联系作者删除!