简体   繁体   中英

AppCompat - Activity.startSupportActionMode not working on pre-ICS devices

This is how it look's in Android 4.4: 在此输入图像描述

And in Android 3.2, it look's like this: 在此输入图像描述

The two buttons is working in 3.2, but not appearing.

I tried to set actionModeBackground to @android:color/white in my theme, but nothing changes in the ActionMode.

My code:

startSupportActionMode(new android.support.v7.view.ActionMode.Callback(){
    @Override
    public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
        MenuInflater inflater = mode.getMenuInflater();
        inflater.inflate(R.menu.action_mode_test, menu);
        return true;
    }
    @Override
    public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
        mode.setTitle("testTitle");
        return true;
    }
    @Override
    public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
        return false;
    }
    @Override
    public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {}
});

R.menu.action_mode_test:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:compat="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/menu_btn1"
        compat:showAsAction="always"
        android:title="Btn1"/>
    <item
        android:id="@+id/menu_btn2"
        compat:showAsAction="ifRoom"
        android:title="Btn2"/>

</menu>

Active theme:

<style name="MyStyle" parent="Theme.AppCompat.Light.DarkActionBar">
</style>

通过更改为AppCompat工具栏解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM