当前位置: 首页>>代码示例>>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;未经允许,请勿转载。