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

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

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

Activity.getTitle介绍

暂无

代码示例

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

/**
 * Invoke this method to register a new view hierarchy.
 * 
 * @param activity
 *            The activity whose view hierarchy/window to register
 * 
 * @see #addWindow(View, String)
 * @see #removeWindow(Activity)
 */
public void addWindow(Activity activity) {
  String name = activity.getTitle().toString();
  if (TextUtils.isEmpty(name)) {
    name = activity.getClass().getCanonicalName() + "/0x" + System.identityHashCode(activity);
  } else {
    name += "(" + activity.getClass().getCanonicalName() + ")";
  }
  addWindow(activity.getWindow().getDecorView(), name);
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
  // Sets color of entry in the system recents page
  try {
    ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(
        (String) activity.getTitle(),
        ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap(),
        color);
    activity.setTaskDescription(td);
  } catch (Exception ignored) {
  }
}

代码示例来源:origin: square/assertj-android

public S hasTitle(CharSequence title) {
 isNotNull();
 CharSequence actualTitle = actual.getTitle();
 assertThat(actualTitle) //
   .overridingErrorMessage("Expected title <%s> but was <%s>.", title, actualTitle) //
   .isEqualTo(title);
 return myself;
}

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

@Test
public void shouldUseActivityLabelFromManifestAsTitleForActivityWithShortName() throws Exception {
 activity = Robolectric.setupActivity(LabelTestActivity3.class);
 assertThat(activity.getTitle()).isNotNull();
 assertThat(activity.getTitle().toString()).isEqualTo(activity.getString(R.string.activity_name));
}

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

@Test
public void shouldUseApplicationLabelFromManifestAsTitleForActivity() throws Exception {
 activity = Robolectric.setupActivity(LabelTestActivity1.class);
 assertThat(activity.getTitle()).isNotNull();
 assertThat(activity.getTitle().toString()).isEqualTo(activity.getString(R.string.app_name));
}

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

@Test
public void shouldUseActivityLabelFromManifestAsTitleForActivity() throws Exception {
 activity = Robolectric.setupActivity(LabelTestActivity2.class);
 assertThat(activity.getTitle()).isNotNull();
 assertThat(activity.getTitle().toString()).isEqualTo(activity.getString(R.string.activity_name));
}

代码示例来源:origin: yanzhenjie/NoHttp

@Override
void setActionBar(Toolbar actionBar) {
  this.mActionBar = actionBar;
  Activity activity = getSource();
  if (mActionBar != null) {
    setTitle(activity.getTitle());
    mActionBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {
        if (mMenuItemSelectedListener != null) {
          mMenuItemSelectedListener.onMenuClick(item);
        }
        return true;
      }
    });
    mActionBar.setNavigationOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (mMenuItemSelectedListener != null) {
          mMenuItemSelectedListener.onHomeClick();
        }
      }
    });
    mActionBarIcon = mActionBar.getNavigationIcon();
  }
}

代码示例来源:origin: JessYanCoding/ArmsComponent

@Override
public void onActivityStarted(Activity activity) {
  Timber.i(activity + " - onActivityStarted");
  if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
    //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
    //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
    activity.getIntent().putExtra("isInitToolbar", true);
    //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
      if (activity instanceof AppCompatActivity) {
        ((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
        ((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
      } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
          activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
          activity.getActionBar().setDisplayShowTitleEnabled(false);
        }
      }
    }
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
      ((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
    }
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
      ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
        activity.onBackPressed();
      });
    }
  }
}

代码示例来源:origin: com.uphyca/android-junit4-robolectric

/**
 * @return
 * @see android.app.Activity#getTitle()
 */
public final CharSequence getTitle() {
  return mActivity.getTitle();
}

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

public void resume(final Activity currentActivity) {
  ttobj = new android.speech.tts.TextToSpeech(currentActivity.getApplicationContext(),
      new android.speech.tts.TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
          if (status != android.speech.tts.TextToSpeech.ERROR) {
            ttobj.setLanguage(Locale.UK);

            speakText(currentActivity.getTitle());
          }
        }
      });           
}

代码示例来源:origin: doc-rj/smartcard-reader

public void onViewParsedMsg(Bundle b) {
  Intent i = new Intent(mActivity, MsgParseActivity.class);
  b.putString("activity", mActivity.getTitle().toString());
  b.putInt("test_mode", mTestMode);
  i.putExtra("parsed_msg", b);
  mActivity.startActivity(i);
}

代码示例来源:origin: doc-rj/smartcard-reader

public void setShareIntent() {
  if (mMsgAdapter != null && mShareProvider != null) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    //Log.d(TAG, mMsgAdapter.getShareMsgsHtml());
    sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(mMsgAdapter.getShareMsgsHtml()));
    // subject for emails
    String subject = mActivity.getString(R.string.app_name) + ": " + mActivity.getTitle();
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.setType("text/html");
    mShareProvider.setShareIntent(sendIntent);
  }
}

代码示例来源:origin: matomo-org/piwik-sdk-android

public static String getBreadcrumbs(final Activity activity) {
  Activity currentActivity = activity;
  ArrayList<String> breadcrumbs = new ArrayList<>();
  while (currentActivity != null) {
    breadcrumbs.add(currentActivity.getTitle().toString());
    currentActivity = currentActivity.getParent();
  }
  return joinSlash(breadcrumbs);
}

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

public static String getBreadcrumbs(final Activity activity) {
  Activity currentActivity = activity;
  ArrayList<String> breadcrumbs = new ArrayList<>();
  while (currentActivity != null) {
    breadcrumbs.add(currentActivity.getTitle().toString());
    currentActivity = currentActivity.getParent();
  }
  return joinSlash(breadcrumbs);
}

代码示例来源:origin: iAcn/BiliNeat

public static void updateTaskColor(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;

    String label = activity.getTitle().toString().trim();
    Bitmap icon = BitmapFactory.decodeResource(activity.getResources(), R.mipmap.ic_launcher);

    if (TextUtils.isEmpty(label)) {
      label = activity.getResources().getString(R.string.app_name);
    }

    activity.setTaskDescription(new ActivityManager.TaskDescription(label, icon, getPrimaryColor()));
  }
}

代码示例来源:origin: com.squareup.assertj/assertj-android

public S hasTitle(CharSequence title) {
 isNotNull();
 CharSequence actualTitle = actual.getTitle();
 assertThat(actualTitle) //
   .overridingErrorMessage("Expected title <%s> but was <%s>.", title, actualTitle) //
   .isEqualTo(title);
 return myself;
}

代码示例来源:origin: rohanoid5/Muzesto

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
  // Sets color of entry in the system recents page
  try {
    ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(
        (String) activity.getTitle(),
        ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap(),
        color);
    activity.setTaskDescription(td);
  } catch (Exception ignored) {
  }
}

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

public static void applyFontForToolbarTitle(Activity context){
  Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
  for(int i = 0; i < toolbar.getChildCount(); i++){
    View view = toolbar.getChildAt(i);
    if(view instanceof TextView){
      TextView tv = (TextView) view;
      Typeface titleFont = Typeface.
        createFromAsset(context.getAssets(), "fonts/customFont");
      if(tv.getText().equals(context.getTitle())){
        tv.setTypeface(titleFont);
        break;
      }
    }
  }
}

代码示例来源:origin: brainysoon/cyberCar

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
  // Sets color of entry in the system recents page
  try {
    ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(
        (String) activity.getTitle(),
        ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap(),
        color);
    activity.setTaskDescription(td);
  } catch (Exception ignored) {
  }
}

代码示例来源:origin: pylerSM/XInstaller

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  oldTitle = (String) getActivity().getTitle();
  getActivity().setTitle(R.string.help);
}

相关文章

Activity类方法