【发布时间】:2016-01-05 14:19:29
【问题描述】:
Erm 我可以在应用栏中切换图标而不是使用切换按钮吗?
当我在应用栏中按下我的图标时,它会变为其他图标
这是我的 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>
主要活动代码
@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);
}
}
【问题讨论】:
-
@2Dee 我该如何解锁?为什么暂停?
标签: android android-studio material-design