如何在选择时突出显示菜单项? [英] how to highlight menu item on selection?

查看:72
本文介绍了如何在选择时突出显示菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个菜单项,我希望它们在选择时突出显示.我尝试使用 item.setIcon(),它工作正常,但是当我选择其他菜单项时,上一个也会突出显示.有可能只突出显示当前选择吗?

I have four menu items and I want them to be highlighted on selection. I tried to use item.setIcon(), it works fine but when I select other menu item, the previous one is also highlighted. Is there any possibility of making only current selection highlighted?

这是我的menu.xml

This is my menu.xml

<item 
    android:id="@+id/home"
    android:showAsAction="always"
    android:title="Home"
    android:icon="@drawable/home72"/>
<item 
    android:id="@+id/location"
    android:showAsAction="always"
    android:title="Locations"
    android:icon="@drawable/locations72"/>
<item
    android:id="@+id/preQualify"
    android:showAsAction="always"
    android:title="Pre-Qualify"
    android:icon="@drawable/prequalify72"/>
<item 
    android:id="@+id/products"
    android:showAsAction="always"
    android:title="Products"
    android:icon="@drawable/products72"/> 

这是我的java文件:

This is my java file:

public boolean onOptionsItemSelected(MenuItem item) {

    switch(item.getItemId()){

    case R.id.home:
        //item.setIcon(icon);
        final ProgressDialog homeDialog = new ProgressDialog(this);
        homeDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        homeDialog.setCancelable(false);

        storeLocator = (WebView) findViewById(R.id.storeLocator);
        storeLocator.setWebViewClient(new WebViewClient());
        storeLocator.getSettings().setJavaScriptEnabled(true);
        //storeLocator.getSettings().setBuiltInZoomControls(true);
        storeLocator.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                homeDialog.show();
                homeDialog.setProgress(0);
                activity.setProgress(progress * 1000);

                homeDialog.incrementProgressBy(progress);

                if(progress == 100 && homeDialog.isShowing())
                    homeDialog.dismiss();
            }
        });
        storeLocator.loadUrl("xxxx");
        //item.setIcon(R.drawable.homew);
        /*Toast.makeText(this, "Home selected", Toast.LENGTH_SHORT)
        .show();*/
        break;

    case R.id.location:
        final ProgressDialog locationDialog = new ProgressDialog(this);
        locationDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        locationDialog.setCancelable(false);

        storeLocator = (WebView) findViewById(R.id.storeLocator);
        storeLocator.setWebViewClient(new WebViewClient());
        storeLocator.getSettings().setJavaScriptEnabled(true);
        //storeLocator.getSettings().setBuiltInZoomControls(true);
        storeLocator.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                locationDialog.show();
                locationDialog.setProgress(0);
                activity.setProgress(progress * 1000);

                locationDialog.incrementProgressBy(progress);

                if(progress == 100 && locationDialog.isShowing())
                    locationDialog.dismiss();
            }
        });
        storeLocator.loadUrl("xxxx");

        //item.setIcon(R.drawable.lcoationw);
        /*Toast.makeText(this, "Location selected", Toast.LENGTH_SHORT)
        .show();*/
        break;
}

推荐答案

是否有可能仅突出显示当前选择?

Is there any possibility of making only current selection highlighted?

跟踪您突出显示的内容.当突出显示一个突出显示时,请从上一个突出显示中删除突出显示.

Keep track of what you have highlighted. When you highlight one, remove the highlight from the previous one.

这篇关于如何在选择时突出显示菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆