4

The title of this question is not exactly reflects my question I have trimmed it because it went too lengthy. Sorry for my bad English too.

Okay,

I am using a library which has an activity, I am using that activity in my app. The orientation of that activity is working fine in tablets i.e., both landscape and portrait but in phones it sticks to portrait mode.

When I have seen the Manifest file of that library its like

<activity
   android:name="DrawingActivity"
   android:configChanges="orientation|keyboardHidden|screenSize"
   android:finishOnTaskLaunch="true"
   android:screenOrientation="unspecified">

In the thread Android Orentation Changes. I came to know it should like android:screenOrientation="fullSensor" to work.

Now I am trying to override the screenOrientation property of the activity as said here

using tools:replace attribute but still its not working. Please can anybody help me to solve this issue.

This is how I'm trying to achieve.

<activity
   android:name="DrawingActivity"
   android:configChanges="orientation|keyboardHidden|screenSize"
   android:finishOnTaskLaunch="true"
   android:screenOrientation="fullSensor"
   tools:replace="android:screenOrientation">

If my question is not clear/too broad please let me know I'll edit my question.

Regards

Community
  • 1
  • 1
ImGenie
  • 323
  • 1
  • 15

5 Answers5

2

You can use tools:node="merge", for example:

<activity android:name="DrawingActivity"
    android:screenOrientation="fullSensor"
    tools:node="merge">
</activity>

this node will be merged with the existing one and overrides any duplicates.

for more details about this refer to https://developer.android.com/studio/build/manifest-merge#node_markers

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
1
<activity
   android:name="DrawingActivity"
   android:configChanges="orientation|keyboardHidden|screenSize"
   android:finishOnTaskLaunch="true"
   android:screenOrientation="fullSensor"
   tools:replace="screenOrientation">

Dont use android:screenOrientation instead use screenOrientation

Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37
0

This will work:

tools:node="replace"

In your case it'd be:

<activity  
   android:name="DrawingActivity"
   android:screenOrientation="fullSensor"
   tools:node="replace" />

It will replace any attr added on the library which in this case will be 'screenOrientation' from 'unspecified' to 'fullSensor'.

César Muñoz
  • 535
  • 1
  • 6
  • 10
0

Try this one:-

<activity android:name="DrawingActivity"
            tools:replace="android:screenOrientation"
            android:screenOrientation="fullSensor">
</activity>
Rishabh
  • 1,827
  • 1
  • 12
  • 9
-1

Import library as module instead of using Gradle, so you can change Code

Akshay Panchal
  • 695
  • 5
  • 15