gpt4 book ai didi

android - 根据系统日历突出显示下拉菜单中的项目 - Android

转载 作者:行者123 更新时间:2023-11-30 01:19:00 25 4
gpt4 key购买 nike

我有一个 10 年的菜单 xml(menu_year.xml),单击按钮(yearbutton)会显示此菜单。如何在菜单中默认突出显示当前年份(从系统日历中获取的年份)?

这是我的 menu_year.xml

<item
android:id="@+id/year2020"
android:title="2020"/>
<item
android:id="@+id/year2019"
android:title="2019"/>
<item
android:id="@+id/year2018"
android:title="2018"/>
<item
android:id="@+id/year2017"
android:title="2017"/>
<item
android:id="@+id/year2016"
android:title="2016"/>
<item
android:id="@+id/year2015"
android:title="2015"/>
<item
android:id="@+id/year2014"
android:title="2014"/>
<item
android:id="@+id/year2013"
android:title="2013"/>
<item
android:id="@+id/year2012"
android:title="2012"/>
<item
android:id="@+id/year2011"
android:title="2011"/>

这是我的java代码

Button yearbutton = (Button) findViewById(R.id.yearbutton);
yearbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final PopupMenu popup_year = new PopupMenu(DateTimeSelect_Activity.this, yearbutton);
popup_year.getMenuInflater()
.inflate(R.menu.menu_year, popup_year.getMenu());
popup_year.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
yearvalue.setText(item.getTitle());
yearvalue.setVisibility(View.VISIBLE);
return true;
}
});
popup_year.show();
}
});

如何在单击 yearbutton 的下拉列表中突出显示 2016 年?提前致谢

最佳答案

已经回答了这个问题 Set selected item background color on Android dropdown navigation检查弹出菜单的背景颜色。

关于android - 根据系统日历突出显示下拉菜单中的项目 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37393531/

25 4 0