Darkrum Darkrum - 2 months ago 18
Android Question

Cordova copy/paste menu is grey

In a cordova app when selecting text and bringing up the copy/paste menu on marshmallow it's background color is not the default white but instead grey. How do you change it back to the default?

Heres a picture for clarity

enter image description here

Answer

I might have a perfect solution for you.

You could use cordova-custom-config-Plugin. After installing it:

cordova plugin add cordova-custom-config

or

phonegap plugin add cordova-custom-config

You can easyly modify an android theme just by modifing your config.xml file. My cordova-testapp uses Holo-Light theme for instance:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.testapp955851" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>testapp</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com.com/">
      Your Name Here
    </author>
    ....
    ....
  <preference name="android-manifest/application/activity/@android:theme" value="@android:style/Theme.Holo.Light" />

</widget>

To see the changings you could test these themes for instance: @android:style/Theme.DeviceDefault, @android:style/Theme.Holo.Light or @android:style/Theme.Holo.


When you want to make your own theme, just use this generator.(it is deprecated but nevertheless good enough for an example).

After generating your own theme, downloading and unzipping it, you have to put all drawable-files into your android project-folder(platforms/android/res). After these style-files are in your project the last thing you have to do is to copy your theme-defintions from your downloaded/unzipped style_example.xml(res/values/style_example.xml) into your project style-file called strings.xml(platforms/android/res/values/strings.xml).

After doing this my strings.xml file looks like this:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">testapp</string>
    <string name="launcher_name">@string/app_name</string>
    <string name="activity_name">@string/launcher_name</string>

    <!-- ONYL PUT style-tags INTO strings.xml -->
    <style name="Theme.YourOwnTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_example</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Example</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Example</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Example</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_example</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_example</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item>
    </style>
.....
.....
</resources>

Furthermore I've renamed this theme Theme.YourOwnTheme to show that you are really using a modified theme. Accordingly I changed the theme-name in config.xml:

<preference name="android-manifest/application/activity/@android:theme" value="@style/Theme.YourOwnTheme" />

Finish!

Although it has been testet on a samsung galaxy S4(Lollipop, version: 5.0.1) it should work on marshmallow as well.

Another helpful link.

Hope this helps.

Comments