我有四个菜单项,我希望它们在选择时突出显示。我试着用
item.setIcon()
,它工作正常,但当我选择其他菜单项时,前一个菜单项也会突出显示。是否有可能仅突出显示当前选择?
这是我的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文件:
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;
}
答案 0 :(得分:2)
是否有可能仅突出显示当前选择?
跟踪您突出显示的内容。高亮显示一个时,请删除上一个高亮显示。