how to fix activities' orientation in tabhost - android

I have meet a problem, there is a tabhost in my app.which have 4 tabs,each tab have more than one activiy.I just want to fix some of activities in portrait mode while other's can change orientation mode,any suggestions?
<activity android:name=".MyTabHost"
android:windowSoftInputMode="adjustPan|stateVisible"
android:configChanges="keyboardHidden|orientation"
></activity>
<!-- android:screenOrientation="portrait" -->
<activity android:name=".Products_Images"
android:configChanges="keyboardHidden|orientation"
></activity>
<activity android:name=".Products_Upload"
android:screenOrientation="portrait"></activity>
<activity android:name=".Products_Description"
android:screenOrientation="portrait"></activity>
in products_images.java,i just want to show larger image while orientation changed,however in products_upload.java and products_description.java,i just want to fix orientation in portrait mode, all three class just in one tab.but it doesnt work!!

use this in activity tag in manifest file:
android:screenOrientation="portrait"

Related

Phones with external keyboard. Prevent change orientation

I have a big issue for those phones that have not only the softkeyboard that all phones have (on screen)... i'm talking about those phones with external keyboard hardware.
in these moment I've set all activities, forcing one way, portrait. Now here comes the problem when the user flips his external keyboard, the activity changes orientation forcing the app to close.
if someone dosn't know which phones i'm talking about here is an example:
Phone with external keyboard
Piece of my manifest;
<activity
android:name=".Splash"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
</activity>
How can make the keyboard to ignore orientation?
Try adding this to your activity manifest.
android:configChanges= "keyboardHidden|orientation"

Issue : Changing screen orientation in different activity

I have the main Activity which has 4 images on the canvas with the screen Orientation as "portrait". When I traverse to the child Activity which has the screen Orientation as "landscape".
Issue : When I come back from the child Activity to the main Activity the 4 images are relocated to different position. I need to resolve this so that the Activity is fine even for the change in screen orientation.
Thanks in Advance.
Layout
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black">
<activity
android:name=".DragDrop"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".QuizHard"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.QUIZHARD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
you can set the orientation to portrait of main activity and landscape of child activity in android manifest file.
<activity android:name="Main"
android:screenOrientation="portrait"/>
similarly set orientation to landscape for child activity.
You can add statements to your AndroidManifest.xml file to tell it to handle certain screen changes, such as orientation changes. Normally, when the orientation changes, a new layout is loaded and the screen is recreated, by adding this statement to the manifest file, it won't recreate the view. Change the activity declaration of your activities and add this statement.
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The android:configChanges="orientation" will prevent Android from recreating the activity, thus preventing it from reloading the view and changing the image positions. You can also add android:screenOrientation="portrait" right after the configChanges statement if you want Android to lock the orientation to portrait, or landscape, if you want.Hope this helps! Would love to hear back from you with the results.
You can add orientation to activity in manifest like this
<activity android:name="Main" android:screenOrientation="portrait"/>
or you can set layout orientation in java file like this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Android Screen Orientation: Landscape Back to Portrait

I have designed an activity that its orientation is landscape. Also I have designed another that its orientation is portrait. When I run in my phone, there are some problems comes to when the landscape activity back to the portrait activity.
Some of the layout disappear, such as below
original:
after
can anyone help me to solve this problem?Thank you so much!
<activity android:name="TestingActivity" android:screenOrientation="portrait" android:configChanges="orientation" > </activity>
<activity android:name="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name=".TestingActivity2" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="landscape" />
Your problem is in layout-portrait xml file. You can fix it by redesigning it. Please post your code.

Programmatically disabling screen rotations in the entire Android application

How do I programmatically disable screen rotations for an entire Android application?
As in keep it in portrait or Landscape no matter which way device is tilted?
You need to add this to your manifest inside the activity that you want to limit
android:screenOrientation="portrait" //Or landscape for horizontal.
If you want it different between activities just make your manifest look like this.
<activity android:name=".Activity1"
android:screenOrientation="landscape">
</activity>
<activity android:name=".Activity2"
android:screenOrientation="portrait">
</activity>
<activity android:name=".Activity3"
android:screenOrientation="landscape">
</activity>
Fix the orientation in android manifest for every activity
<activity android:name=".SomeNewDesignActivity"
android:screenOrientation="portrait" ></activity>
Too late to the party!
Anyway if you want to disable rotation without forcing the user to choose landscape or portrait you can use in each activity in the manifest
android:screenOrientation="locked"
So your manifest should look like this
<activity android:name=".Activity1"
android:screenOrientation="locked">
</activity>
<activity android:name=".Activity2"
android:screenOrientation="locked">
</activity>
<activity android:name=".Activity3"
android:screenOrientation="locked">
</activity>
So the app will keep the current orientation the user decided to use.
The same behaviour can be obtained programamtically:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Best way to do screen orientation to potrait/landscap for entire app -
Add following lines in your app theme -
for making all activity portrait -
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:screenOrientation">portrait</item>
</style>
for making all activity landscape -
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:screenOrientation">landscape</item>
</style>

android keyboard not adjust/pan working android:windowSoftInputMode=

<activity android:name="com.jony.ViewMessages"
android:label="#string/app_name" android:screenOrientation="landscape"
android:configChanges="orientation"
android:windowSoftInputMode="stateUnspecified|adjustUnspecified" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>
Adjust Pan or resize is not working and it is hiding all my text view and that I don't want. Here is another post that declares it a bug.
See This related post please
just try this
<activity android:name="com.jony.ViewMessages"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustPan">
</activity>

Categories

Resources