Problem
First my ActionBar (with custom menu) is purple, then:
- Trigger CAB by long-click on my ListView
- Change phone orientation
- Cancel CAB
ActionBar becomes white. This does not happen without phone orientation change. I have tried this on android 4.4.4
, minSdkVersion="19"
, targetSdkVersion="26"
. Can you please advise me, why this could happen?
UPDATE: Tried on API 25 emulator, and this does not happen.
Sources
Activity layout:
<android.support.constraint.ConstraintLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="sk.tuke.smart.makac.activities.FreeShootingHistoryActivity">
<ListView
android:id="@+id/listview_freeshootinghistory"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@android:layout/simple_list_item_activated_2" />
</android.support.constraint.ConstraintLayout>
switch_menu.xml
- classic Action Bar:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item_switchmenu_label"
android:title="@string/switchmenu_colouring"
app:showAsAction="ifRoom" />
<item
android:id="@+id/item_switchmenu_switch"
android:title="@string/switchmenu_colouring"
app:actionViewClass="android.support.v7.widget.SwitchCompat"
app:showAsAction="always" />
</menu>
delete_menu.xml
- Contextual Action Bar:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/item_deletemenu_delete"
android:icon="@drawable/ic_action_delete"
android:title="@string/deletemenu_delete" />
</menu>
initializing ActionBar in activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.switch_menu, menu);
//...stuff...
return true;
}
setting up CAB in onCreate()
:
historyListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
historyListView.setMultiChoiceModeListener(choiceModeListener);
inside MultiChoiceModeListener
:
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate the menu for the CAB
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.delete_menu, menu);
//...stuff...
return true;
}
in <application>
inside Manifest this style is set android:theme="@style/AppTheme"
from styles.xml
:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#8600b3</item>
<item name="colorPrimaryDark">#730099</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
<item name="android:colorBackground">#bfc6f6</item>
<item name="android:textColorSecondary">@color/text_color_secondary</item>
</style>
</resources>