Erm instead of using toggle button can I toggle icon in app bar instead?
like when I pressed my icon in the app bar it will change to other icon
Here is my 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>
Code on main 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);
}
}