Quispie
Quispie

Reputation: 1009

Cordova 6.3.1 plugin.xml set android-theme doesn't work

Since the <edit-config> tag doesn't work in cordova plugin.xml files and I've tried to use this method to update the android:theme:

<config-file target="res/xml/config.xml" parent="/*">
  <application>
    <preference name="android-theme" value="@style/Theme.AppCompat.NoActionBar"/>
  </application>
</config-file>

This code doesn't work even if I set the parent to /Application or remove the application tags

How can I change the "android-theme" tag inside the android manifest?
(dummy code):

<manifest>
  <application>
    <activity android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
  </application>
</manifest>

UPDATE

I've updated to cordova 6.4.0 and tried to use this sample code:

<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
    <uses-sdk android:minSdkVersion="16" android:maxSdkVersion="23" />
</edit-config>

This works, however when I try to use it for the android:theme attribute:

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity" mode="overwrite">
    <activity android:theme="@style/Theme.AppCompat.NoActionBar" />
</edit-config>

it gives this java error:

Error: Cannot read property 'length' of undefined

Upvotes: 2

Views: 1664

Answers (3)

Quispie
Quispie

Reputation: 1009

Using the answer of Gandhi I've updated my node application to the latest version and updated the plugin.xml to this:

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="merge">
   <activity android:theme="@style/Theme.AppCompat.NoActionBar" />
</edit-config>

This works perfect!

Upvotes: 0

Gandhi
Gandhi

Reputation: 11935

I tried it out after upgrading my setup from Cordova 6.2 to Cordova 6.4.0 It works for me. I tried both the case of merge and overwrite mode in edit-config.

To test this functionality, I created a new barebone corodva project using Cordova CLI. Then, i installed cordova device plugin in the project. After installing the plugin, i tweaked the plugin.xml of cordova device plugin and added the following inside android platform tag:

<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
            <uses-sdk  android:maxSdkVersion="25" />
</edit-config>
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="overwrite">
             <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize"/>
</edit-config>

After tweaking the plugin.xml, I added Android platform using cordova platform add android command. After the successful addition of android platform, I opened the AndroidManifest.xml available under platforms\android folder and the contents mentioned in edit-config were updated in it. The XML file is as follows:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:maxSdkVersion="25" android:minSdkVersion="16" android:targetSdkVersion="24" />
</manifest>

Have also tried removing and re-adding the android platform, it works. In your case you are using Cordova 6.3.1 and i m not sure whether its an issue with cordova. Hope it will work if you could upgrade to Cordova 6.4.0

Also my node version is 6.9.2 and cordova android version is 6.0.0

Hope it helps. Cheers

Upvotes: 3

Pritish Vaidya
Pritish Vaidya

Reputation: 22209

You can try using the cordova-custom-plugin particularly made for this purpose only by changing the platform config data based upon the preferences in the config.xml

Install it by using the following command as mentioned in the particular plugin link

As mentioned it would apply the attribute android:theme in the following way

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

in your android-manifest -- application -- activity

Upvotes: 0

Related Questions