gpt4 book ai didi

android - 如何在android studio的应用栏上切换菜单图标

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

<分区>

呃,我可以在应用栏中切换图标而不是使用切换按钮吗?

就像我在应用栏中按下我的图标时它会变成其他图标

这是我的 menu_main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="course.examples.healthcare_application.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="1"
android:title="@string/action_settings"
app:showAsAction="never" />

<!--lower value will be on the left-->
<item
android:id="@+id/Bluetooth_connect"
android:icon="@drawable/ic_bluetooth_white_24dp"
app:showAsAction="always"
android:orderInCategory="2"
android:title="@string/bluetooth_connect" />
</menu>

主要 Activity 代码

 @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement

if(id == R.id.Bluetooth_connect){
Toast.makeText(getApplicationContext(), "Turned on", Toast.LENGTH_LONG).show();

}

return super.onOptionsItemSelected(item);
}
}

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