當前位置: 首頁>>代碼示例>>Java>>正文


Java MenuItem.getIcon方法代碼示例

本文整理匯總了Java中android.view.MenuItem.getIcon方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItem.getIcon方法的具體用法?Java MenuItem.getIcon怎麽用?Java MenuItem.getIcon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MenuItem的用法示例。


在下文中一共展示了MenuItem.getIcon方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onOptionsItemSelected

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    switch (item.getItemId()) {
        case R.id.action_cut:
            return true;
        case R.id.action_copy:
            return true;
        case R.id.action_share:
            return true;
        case R.id.action_delete:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:MainActivity.java

示例2: onSubMenuSelected

import android.view.MenuItem; //導入方法依賴的package包/類
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
        MenuPopupHelper subPopup = new MenuPopupHelper(this.mContext, subMenu, this.mAnchorView);
        subPopup.setCallback(this.mPresenterCallback);
        boolean preserveIconSpacing = false;
        int count = subMenu.size();
        for (int i = 0; i < count; i++) {
            MenuItem childItem = subMenu.getItem(i);
            if (childItem.isVisible() && childItem.getIcon() != null) {
                preserveIconSpacing = true;
                break;
            }
        }
        subPopup.setForceShowIcon(preserveIconSpacing);
        if (subPopup.tryShow()) {
            if (this.mPresenterCallback != null) {
                this.mPresenterCallback.onOpenSubMenu(subMenu);
            }
            return true;
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:MenuPopupHelper.java

示例3: setMenuIconColor

import android.view.MenuItem; //導入方法依賴的package包/類
/**
 * this method changes the icon color of a MenuItem.
 */
public ReColor setMenuIconColor(MenuItem menuItem, String startingColor, String endingColor, int duration) {

    try {
        if (duration < 16)
            throw new ReColorException("\n \n      duration must at least be 16ms \n ");
        this.startingColor = getValidColor(startingColor, "start");
        this.endingColor = getValidColor(endingColor, "end");
        if (this.startingColor != null && this.endingColor != null) {
            this.menuItem = menuItem;
            menuItemIcon = menuItem.getIcon();
            if (menuItemIcon == null)
                throw new ReColorException("\n \n      menuItem doesn't have an icon \n ");
            stepCount = duration / colorChangeSpeed;
            colorArray = getColorArray(this.startingColor, this.endingColor, stepCount);
            timerHandler.postDelayed(menuIconColorTimerRunnable, 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return this;
}
 
開發者ID:SIMMORSAL,項目名稱:ReColor,代碼行數:26,代碼來源:ReColor.java

示例4: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.reading, menu);
    MenuItem invert = menu.findItem(R.id.invert_item);
    MenuItem textSize = menu.findItem(R.id.text_size_item);

    int iconColor = ThemeUtils.getIconThemeColor(this, mInvert);

    if (invert != null && invert.getIcon() != null) {
        invert.getIcon().mutate().setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
    }

    if (textSize != null && textSize.getIcon() != null) {
        textSize.getIcon().mutate().setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
    }

    return super.onCreateOptionsMenu(menu);
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:19,代碼來源:ReadingActivity.java

示例5: onOptionsItemSelected

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    return super.onOptionsItemSelected(item);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:MainActivity.java

示例6: tintMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, final @ColorInt int color) {
    try {
        final Field field = Toolbar.class.getDeclaredField("mCollapseIcon");
        field.setAccessible(true);
        Drawable collapseIcon = (Drawable) field.get(toolbar);
        if (collapseIcon != null) {
            field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // credits: https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        // We can't iterate through the toolbar.getMenu() here, because we need the ActionMenuItemView. ATEActionMenuItemView is overriding the item icon tint color.
        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            ((ActionMenuItemView) innerView).getCompoundDrawables()[k].setColorFilter(colorFilter);
                        }
                    }
                }
            }
        }
    }

    if (menu == null)
        menu = toolbar.getMenu();
    if (menu != null && menu.size() > 0) {
        for (int i = 0; i < menu.size(); i++) {
            final MenuItem item = menu.getItem(i);
            // We must iterate through the toolbar.getMenu() too, to keep the tint when resuming the paused activity.
            if (item.getIcon() != null) {
                item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color));
            }
            // Search view theming
            if (item.getActionView() != null && (item.getActionView() instanceof android.widget.SearchView || item.getActionView() instanceof android.support.v7.widget.SearchView)) {
                SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color);
            }
        }
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:50,代碼來源:ToolbarProcessor.java

示例7: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu);
    MenuItem next = menu.findItem(R.id.menu_crop);
    Drawable defaultIcon = next.getIcon();
    if (defaultIcon != null) {
        defaultIcon.mutate();
        defaultIcon.setColorFilter(this.mToolbarTextColor, Mode.SRC_ATOP);
        next.setIcon(defaultIcon);
    }
    return true;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:12,代碼來源:UCropActivity.java

示例8: tintMenuIcon

import android.view.MenuItem; //導入方法依賴的package包/類
public static void tintMenuIcon(Context context, MenuItem item, int color) {
    Drawable drawable = item.getIcon();
    if (drawable != null) {
        // If we don't mutate the drawable, then all drawable's with this id will have a color
        // filter applied to it.
        drawable.mutate();
        drawable.setColorFilter(ContextCompat.getColor(context, color), PorterDuff.Mode.SRC_ATOP);
    }
}
 
開發者ID:zzzmobile,項目名稱:VideoDownloader-Android,代碼行數:10,代碼來源:iUtils.java

示例9: updateToolbarColor

import android.view.MenuItem; //導入方法依賴的package包/類
private void updateToolbarColor() {

        if (toolbar == null || collapsingToolbarLayout == null) {
            return;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            int[] colors = ColorUtils.get2ToolbarTextColors(this);

            int mainTC = colors[0];
            collapsingToolbarLayout.setCollapsedTitleTextColor(mainTC);
            Drawable navD = toolbar.getNavigationIcon();
            if (navD != null) {
                navD.setTint(mainTC);
            }

            int menuCount = menu.size();
            int mainC = colors[0];
            for (int i = 0; i < menuCount; i++) {
                MenuItem item = menu.getItem(i);
                if (item != null) {
                    Drawable icon = item.getIcon();
                    if (icon != null) {
                        icon.setTint(mainC);
                    }
                }
            }
        }
    }
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:31,代碼來源:SheetDetailActivity.java

示例10: addActions

import android.view.MenuItem; //導入方法依賴的package包/類
/**
 * Add actions to the QuickActionView from the given menu resource id.
 *
 * @param menuId menu resource id
 * @return the QuickActionView
 */
public QuickActionView addActions(@MenuRes int menuId) {
    Menu menu = new MenuBuilder(mContext);
    new MenuInflater(mContext).inflate(menuId, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Action action = new Action(item.getItemId(), item.getIcon(), item.getTitle());
        addAction(action);
    }
    return this;
}
 
開發者ID:ovenbits,項目名稱:QuickActionView,代碼行數:17,代碼來源:QuickActionView.java

示例11: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu, menu);
    MenuItem searchItem = menu.findItem(R.id.search);
    mSearchItemIcon = searchItem.getIcon();
    mSearchView.setMenuItem(searchItem);
    return true;
}
 
開發者ID:crazysunj,項目名稱:MultiTypeRecyclerViewAdapter,代碼行數:10,代碼來源:NormalActivity.java

示例12: onPrepareOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (menu.size() == 1) {
        MenuItem item = menu.getItem(0);
        if (item.getIcon() != null) item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
    return super.onPrepareOptionsMenu(menu);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:9,代碼來源:Preferences.java

示例13: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.album, menu);
    this.menu = menu;

    if (pick_photos) {
        menu.findItem(R.id.share).setVisible(false);
        menu.findItem(R.id.exclude).setVisible(false);
        menu.findItem(R.id.pin).setVisible(false);
        menu.findItem(R.id.rename).setVisible(false);
        menu.findItem(R.id.copy).setVisible(false);
        menu.findItem(R.id.move).setVisible(false);
    } else if (album != null) {
        setupMenu();
    }

    int sort_by = Settings.getInstance(this).sortAlbumBy();
    if (sort_by == SortUtil.BY_DATE) {
        menu.findItem(R.id.sort_by_date).setChecked(true);
    } else if (sort_by == SortUtil.BY_NAME) {
        menu.findItem(R.id.sort_by_name).setChecked(true);
    }

    MenuItem selectAll = menu.findItem(R.id.select_all);
    Drawable d = selectAll.getIcon();
    DrawableCompat.wrap(d);
    DrawableCompat.setTint(d, accentTextColor);
    DrawableCompat.unwrap(d);

    return super.onCreateOptionsMenu(menu);
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:32,代碼來源:AlbumActivity.java

示例14: tint

import android.view.MenuItem; //導入方法依賴的package包/類
/**
 * Tint all menu items within a menu to be a certain color. Note that this does not tint the
 * overflow menu. Call {@link #tintOverflow(Toolbar, int)} for that.
 *
 * @param menu  the menu
 * @param color the color
 */
public static void tint(@NonNull Menu menu, @ColorInt int color) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        if (menuItem.getIcon() != null) {
            tint(menuItem, color);
        }
    }
}
 
開發者ID:jumaallan,項目名稱:AndelaTrackChallenge,代碼行數:16,代碼來源:Easel.java

示例15: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_compile, menu);
    for (int c = 0; c < menu.size(); c++) {
        MenuItem item = menu.getItem(c);
        Drawable drawable = item.getIcon();
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, ContextCompat.getColor(this, R.color.colorAccent));
        item.setIcon(drawable);
    }
    return true;
}
 
開發者ID:solkin,項目名稱:minion-android,代碼行數:13,代碼來源:CompileActivity.java


注:本文中的android.view.MenuItem.getIcon方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。