gpt4 book ai didi

Android 可检查菜单项

转载 作者:IT老高 更新时间:2023-10-28 13:23:16 26 4
gpt4 key购买 nike

我的 Android 应用中有以下菜单布局:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1"
android:titleCondensed="Options"
android:title="Highlight Options"
android:icon="@android:drawable/ic_menu_preferences" />

<item android:id="@+id/item2"
android:titleCondensed="Persist"
android:title="Persist"
android:icon="@android:drawable/ic_menu_preferences"
android:checkable="true" />
</menu>

我的问题是,当我在 Android 模拟器中运行我的应用程序时,第二个菜单项似乎不是“可检查的”。该项目应该有一个绿色的勾号,对吧?表明它是可检查的。

我做错了吗?

最佳答案

布局看起来不错。但是你必须在代码中选中和取消选中菜单项。

来自 documentation :

When a checkable item is selected, the system calls your respective item-selected callback method (such as onOptionsItemSelected()). It is here that you must set the state of the checkbox, because a checkbox or radio button does not change its state automatically. You can query the current state of the item (as it was before the user selected it) with isChecked() and then set the checked state with setChecked().

关于Android 可检查菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6239163/

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