android.view.MenuItem#getTitle ( )源码实例Demo

下面列出了android.view.MenuItem#getTitle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ans-android-sdk   文件: ViewClickProbe.java
@Override
public void trackMenuItem(Object object, MenuItem menuItem, boolean hasTrackClickAnn,long currentTime) {
    try {
        if (isTrackClickSwitchClose()) {
            return;
        }

        Object pageObj = null;
        if (!AllegroUtils.isPage(object)) {
            pageObj = AllegroUtils.getPageObjFromView(null);
        }

        if (!checkTrackClickEnable(pageObj, menuItem, hasTrackClickAnn)) {
            return;
        }

        Map<String, Object> elementInfo = new HashMap<>();
        elementInfo.put(Constants.ELEMENT_TYPE, "MenuItem");
        CharSequence title = menuItem.getTitle();
        if (!TextUtils.isEmpty(title)) {
            elementInfo.put(Constants.ELEMENT_CONTENT, title);
        }
        String idName = AllegroUtils.getIdResourceName(menuItem.getItemId());
        if (!TextUtils.isEmpty(idName)) {
            elementInfo.put(Constants.ELEMENT_ID, idName);
        }
        autoTrackClick(pageObj, elementInfo, hasTrackClickAnn,currentTime);
    } catch (Throwable ignore) {
        ExceptionUtil.exceptionThrow(ignore);
    }
}
 
源代码2 项目: tracker-control-android   文件: ActivityMain.java
private void markPro(MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, this)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
源代码3 项目: tracker-control-android   文件: AdapterRule.java
private void markPro(Context context, MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
源代码4 项目: NetGuard   文件: AdapterRule.java
private void markPro(Context context, MenuItem menu, String sku) {
    if (sku == null || !IAB.isPurchased(sku, context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}
 
源代码5 项目: FireFiles   文件: FabSpeedDial.java
private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
            .inflate(getMenuItemLayoutId(), this, false);

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    FrameLayout cardView = (FrameLayout) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        //cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);
    if (Utils.hasLollipop()) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}
 
源代码6 项目: Carbon   文件: NavigationView.java
public Item(MenuItem item) {
    id = item.getItemId();
    icon = item.getIcon();
    tint = MenuItemCompat.getIconTintList(item);
    groupId = item.getGroupId();
    title = item.getTitle();
}
 
源代码7 项目: Camera-Roll-Android-App   文件: ItemActivity.java
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (theme.isBaseLight()) {
        int black = ContextCompat.getColor(this, R.color.black);
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            SpannableString s = new SpannableString(item.getTitle());
            s.setSpan(new ForegroundColorSpan(black), 0, s.length(), 0);
            item.setTitle(s);
        }
    }
    return super.onPrepareOptionsMenu(menu);
}
 
源代码8 项目: science-journal   文件: MainActivity.java
private CharSequence getTitleToRestore(MenuItem menuItem) {
  if (menuItem.getItemId() == R.id.navigation_item_experiments) {
    return getResources().getString(R.string.app_name);
  } else {
    return menuItem.getTitle();
  }
}
 
源代码9 项目: RedReader   文件: CommentListingFragment.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {

	if(item.getTitle() != null
			&& item.getTitle().equals(getActivity().getString(R.string.action_reply))) {

		onParentReply();
		return true;
	}

	return false;
}
 
@SuppressWarnings("RestrictTo")
public void showChooseThemePopup(View anchor) {
  PopupMenu popupMenu = new PopupMenu(context, anchor);
  popupMenu.inflate(R.menu.mtrl_choose_theme_menu);
  if (popupMenu.getMenu() instanceof MenuBuilder) {
    MenuBuilder menuBuilder = (MenuBuilder) popupMenu.getMenu();

    menuBuilder.setOptionalIconsVisible(true);

    ColorStateList defaultColor =
        AppCompatResources.getColorStateList(
            context, R.color.material_on_surface_emphasis_medium);
    int selectedColor = MaterialColors.getColor(anchor, resourceProvider.getPrimaryColor());
    int currentThemeId = getCurrentThemeId();
    for (int i = 0; i < menuBuilder.size(); i++) {
      MenuItem item = menuBuilder.getItem(i);
      if (item.getItemId() == currentThemeId) {
        DrawableCompat.setTint(item.getIcon(), selectedColor);

        SpannableString s = new SpannableString(item.getTitle());
        s.setSpan(new ForegroundColorSpan(selectedColor), 0, s.length(), 0);
        item.setTitle(s);
      } else {
        DrawableCompat.setTintList(item.getIcon(), defaultColor);
      }
    }
  }
  popupMenu.setOnMenuItemClickListener(
      item -> {
        saveAndApplyTheme(item.getItemId());
        return false;
      });
  popupMenu.show();
}
 
源代码11 项目: Carbon   文件: BottomNavigationView.java
public Item(MenuItem menuItem) {
    id = menuItem.getItemId();
    try {   // breaks preview
        this.icon = menuItem.getIcon();
    } catch (Exception e) {
    }
    this.text = menuItem.getTitle();
    iconTint = MenuItemCompat.getIconTintList(menuItem);
}
 
源代码12 项目: shortyz   文件: HTMLActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getTitle() == null){
        finish();
        return true;
    }
    return false;
}
 
源代码13 项目: guarda-android-wallets   文件: MainActivity.java
private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new RobotoLightTypefaceSpan("", font), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
源代码14 项目: fab-speed-dial   文件: FabSpeedDial.java
private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
            .inflate(getMenuItemLayoutId(), this, false);

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(ContextCompat.getColorStateList(getContext(),
                miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}
 
源代码15 项目: Cook-It-Android-XML-Template   文件: Main.java
private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/SourceSansPro-Semibold.otf");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(),  Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
源代码16 项目: Carbon   文件: FloatingActionMenu.java
public Item(MenuItem item) {
    icon = item.getIcon();
    tint = MenuItemCompat.getIconTintList(item);
    enabled = item.isEnabled();
    title = item.getTitle();
}
 
源代码17 项目: BottomSheetMenu   文件: BottomSheetUtils.java
public static void setMenuItemTextColor(MenuItem menuItem, @ColorInt int textColor) {
    SpannableString s = new SpannableString(menuItem.getTitle());
    s.setSpan(new ForegroundColorSpan(textColor), 0, s.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    menuItem.setTitle(s);
}
 
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
                                                 int itemTextColor, int itemBackground,
                                                 int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();
    mTitles = 0;

    boolean addedSubMenu = false;

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);

        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                SubMenu subMenu = item.getSubMenu();

                if (i != 0 && addedSubMenu) {
                    if (mMode == BottomSheetBuilder.MODE_GRID) {
                        throw new IllegalArgumentException("MODE_GRID can't have submenus." +
                                " Use MODE_LIST instead");
                    }
                    items.add(new BottomSheetDivider(dividerBackground));
                }

                CharSequence title = item.getTitle();
                if (title != null && !title.equals("")) {
                    items.add(new BottomSheetHeader(title.toString(), titleTextColor));
                    mTitles++;
                }

                for (int j = 0; j < subMenu.size(); j++) {
                    MenuItem subItem = subMenu.getItem(j);
                    if (subItem.isVisible()) {
                        items.add(new BottomSheetMenuItem(subItem, itemTextColor,
                                itemBackground, tintColor));
                        addedSubMenu = true;
                    }
                }
            } else {
                items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
            }
        }
    }

    return items;
}
 
源代码19 项目: FaceT   文件: ShopListActivity.java
private void applyFontToMenuItem(MenuItem mi) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypeFaceSpan("", fontType), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}
 
源代码20 项目: FaceT   文件: MainActivity.java
private void applyFontToMenuItem(MenuItem mi) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypeFaceSpan("", fontType), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}