在Android 14中,如何實(shí)現(xiàn)下拉菜單的禁用和啟用? 安卓 下拉菜單
Officeworks跨境辦公港跨境問答2025-07-022130
在Android 14中,下拉菜單的禁用和啟用可以通過設(shè)置android:enabled
屬性來實(shí)現(xiàn)。
以下是一個(gè)簡單的示例:
<com.example.myapplication.MyActivity>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings"
android:title="@string/action_settings"
app:enabled="true" />
</menu>
</com.example.myapplication.MyActivity>
在這個(gè)例子中,我們?yōu)?code>action_settings菜單項(xiàng)設(shè)置了app:enabled="true"
屬性,使其處于啟用狀態(tài)。如果你想禁用某個(gè)菜單項(xiàng),只需將其設(shè)置為app:enabled="false"
即可。
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。