gpt4 book ai didi

android - 如何在选择时突出显示菜单项?

转载 作者:行者123 更新时间:2023-11-29 21:46:23 24 4
gpt4 key购买 nike

我有四个菜单项,我希望它们在选择时突出显示。我试着用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;
}

最佳答案

Is there any possibility of making only current selection highlighted?

记录您突出显示的内容。当您突出显示一个时,从前一个中删除突出显示。

关于android - 如何在选择时突出显示菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15708382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com