Currently the action mode toolbar shows above the toolbar, moving the whole layout down, and I want it to show on top of my current toolbar. I tried all solutions in this post and this one:
- I tried using
windowActionModeOverlay
with and withoutandroid:
prefix, no success - I tried both
view.ActionMode
andsupport.v7.view.ActionMode
, no success - I tried using startActionMode both on my toolbar and my activity, neither worked.
setContentView
is called beforesuper.onCreate
, this is not the problem
Right now I just set toolbar visibility manually, which looks awful. Also I set the activity theme before super.onCreate
, could it be the problem? If not what is it? How can I make the attribute work?
My activity:
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
// import ...
public class FileExplorerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_NoActionBar);
super.onCreate(savedInstanceState);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// ...
}
private void setActionMode(boolean enabled) {
if (enabled) {
actionMode = startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.cab, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// ... change icons color for theme
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// ... handle item clicks
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {}
});
} else {
actionMode.finish();
}
}
}
My theme:
<style name="Theme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="android:actionModeBackground">?attr/colorPrimary</item>
<item name="android:actionModeSplitBackground">@null</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
</style>