- Common ways to obtain Activity
private void myMethod () {Activity a =
WeakReference mActivity;mActivity.get()
Stack activityStack;activityStack.lastElement()
(Activity) param.thisObject
- Smart code suggestions by Codota
}
public void setTitle(CharSequence title) { activity.setTitle(title); } }
@Override public void onReceivedTitle(WebView view, String title) { ((Activity) mContext).setTitle(title); }
getWindow().requestFeature(Window.FEATURE_PROGRESS); WebView mWebView = (WebView) findViewById(R.id.mywebview); mWebView.getSettings().setJavaScriptEnabled(true); final Activity activity = this; mWebView.setWebChromeClient(new WebChromeClient(){ public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if(progress == 100) activity.setTitle("My title"); } }); mWebView.loadUrl(URL);
mActivity .setTitle("Loading..."); mActivity .setProgress(progress * 100); //Make the bar disappear after URL is loaded
mActivity.setTitle(mModes[mModeIndex].toString());
/** * @param titleId * @see android.app.Activity#setTitle(int) */ public void setTitle(int titleId) { mActivity.setTitle(titleId); }
activity.setTitle(activity.getClass().getName());
private void changeTitle(DynamicApkParser.Activity a, Activity activity) { if (a.info.labelRes != 0) { activity.setTitle(a.owner.resources.getString(a.info.labelRes)); } else if (a.owner.applicationInfo.nonLocalizedLabel != null) { activity.setTitle(a.owner.applicationInfo.nonLocalizedLabel); } else if (a.owner.applicationInfo.labelRes != 0) { activity.setTitle(a.owner.resources.getString(a.owner.applicationInfo.labelRes)); } } }
Activity activity = this.getActivity(); Toolbar toolbar = (Toolbar) activity.findViewById(R.id.detail_toolbar); if (toolbar != null) { activity.setTitle("Title"); } //toolbar.setTitle("Title"); did not give the same results
@Override public void onReceivedTitle(WebView view, String title) { System.out.println("网页title:"+title); activity.setTitle(title); super.onReceivedTitle(view, title); } });
@Override public void onReceivedTitle(WebView view, String title) { System.out.println("网页title:"+title); activity.setTitle(title); super.onReceivedTitle(view, title); } });
@Override public void onReceivedTitle(final WebView view, final String title) { final Context context = view.getContext(); if (context instanceof Activity) { ((Activity) context).setTitle(title); } }
public static void resetActivityTitle(Activity a) { try { ActivityInfo info = a.getPackageManager().getActivityInfo(a.getComponentName(), GET_META_DATA); if (info.labelRes != 0) { a.setTitle(info.labelRes); } } catch (NameNotFoundException e) { e.printStackTrace(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.legal_information_preferences); getActivity().setTitle(R.string.legal_information_title); } }
public static void translateTitle(Activity activity) { if (isLocaleOverridden(activity)) { // http://stackoverflow.com/questions/22884068/troubles-with-activity-title-language try { int labelRes = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).labelRes; activity.setTitle(labelRes); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }
@Override public void onResume() { super.onResume(); getActivity().setTitle(getArguments().getString(TITLE)); }
/** * Updates the state of 2 control buttons in response to the current page index. */ private void updateUi() { int index = mCurrentPage.getIndex(); int pageCount = mPdfRenderer.getPageCount(); mButtonPrevious.setEnabled(0 != index); mButtonNext.setEnabled(index + 1 < pageCount); getActivity().setTitle(getString(R.string.app_name_with_index, index + 1, pageCount)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.physical_web_preferences); getActivity().setTitle(R.string.physical_web_pref_title); initPhysicalWebSwitch(); initLaunchButton(); }
@Override public void onResume() { super.onResume(); getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); if (mShowExperimental != ConfigUtils.showExperimental(ConfigUtils.getPreferences(getActivity()))) { getActivity().recreate(); } else { getActivity().setTitle(R.string.app_name); } }
@Override public void onStop() { getActivity().setTitle(oldTitle); ActionBar ab = getActivity().getActionBar(); if (ab != null && oldTitle.equals(getString(R.string.app_name))) { ab.setDisplayHomeAsUpEnabled(false); ab.setHomeButtonEnabled(false); } getActivity().invalidateOptionsMenu(); super.onStop(); } }