How to display menu item Icons on Android 9 in Floating Action Mode
Asked Answered
I

0

6

I have an Android menu XML that resembles this:-

<item
    android:id="@+id/action_share"
    android:orderInCategory="100"
    android:icon="@drawable/ic_social_share"
    app:showAsAction="always"
    android:title="" />

<item
    android:id="@+id/action_something_else"
    android:orderInCategory="200"
    android:icon="@drawable/ic_airplanemode_active_black_24dp"
    app:showAsAction="always"
    android:title="" />

My Android code resembles this:-

   private void startActionMode() {
        startActionMode(new android.view.ActionMode.Callback2() {
            @Override
            public boolean onCreateActionMode(final android.view.ActionMode mode, final Menu menu) {
                MenuInflater inflater = mode.getMenuInflater();
                inflater.inflate(R.menu.main, menu);
                mode.setTitle("FLOATING!!!!!");
                return true;
            }

            @Override
            public boolean onPrepareActionMode(final android.view.ActionMode actionMode, final Menu menu) {
                return false;
            }

            @Override
            public boolean onActionItemClicked(final android.view.ActionMode actionMode, final MenuItem menuItem) {
                return false;
            }

            @Override
            public void onDestroyActionMode(final android.view.ActionMode actionMode) {

            }
        }, android.view.ActionMode.TYPE_FLOATING);
    }

When I deploy my Android application to a Android 8 device the floating action mode shows the icons as required.

However, when I deploy my Android application to a Android 9 device the floating action mode is empty, although there is space for the icons and I can see the background ripple effect where the icons should be.

How do you employ android.view.ActionMode.TYPE_FLOATING on Android 9 and see the icons for each menu item?

my gradle file resembles this:-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "org.research.development"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
}

heres my applications style

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowDisablePreview">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="actionMenuTextColor">@android:color/white</item>
    <item name="android:windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!--  It should be true otherwise action mode will not overlay toolbar -->
    <item name="windowActionModeOverlay">true</item>

    <!--  For Custom Action Mode Background Color/Drawable -->
    <item name="actionModeBackground">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Immersed answered 5/3, 2019 at 14:23 Comment(1)
which style are you using for the toolbar?Cigarillo

© 2022 - 2024 — McMap. All rights reserved.