When my android phone is landscape,the screen size change,how to stop it?I kown that had edit manifest "configChanges",activity not start itself life again,but the display size had chang.
Just add in AndroidManifest.xml in activity tag:
<activity
android:name="MyActivity"
android:screenOrientation="portrait"/>
Add android:screenOrientation="portrait" to the element/s in the manifest . This will solve your problem. Or if you want your activity in always landscape mode you can add android:screenOrientation="landscape"
Related
i want to change the app name. Not every where. only in the launcher screen of an android.
Not inside the app or in the installation screen.
is this possible?
Your Manifest.xml file should be similar to this:
<application
....
<activity
android:name=".activities.SplashScreenActivity"
android:label="myLabel"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
....
....
As you can see every Activity node has a label attribute. Changing this changes only the activity label (not all over the application)
Set the android:label attribute of the main Activity in your Android Manifest (the one that starts when the Launcher icon is pressed)
I'm currently working on writing an Android Things app and installing it on a Raspberry Pi 3. I have it connected to monitor, but I want to be able to hang the monitor in a portrait orientation, rather than landscape. I've tried adding the following line to the AndroidManifest.xml under activity:
android:screenOrientation="portrait"
However, this doesn't seem to affect how the activity is displayed on the screen. Is there a way to change the orientation to portrait in an Android Things project?
you can do it something like below
After rootView in your java add this line
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
For Ex:
View rootView = inflater.inflate(R.layout.activityxml, container, false);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And also in your manifest change it
android:configChanges="orientation|keyboardHidden" as
android:configChanges="keyboardHidden"
<activity
android:name="com.test.activity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden" >
I change
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
to
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
But why it can not change orientation?
If use android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen", it can change orientation.
But if change to another one, it can't.
I try it in Android 2.3.4.
But in Android 4.0.2, it works success on change orientation.
Why and how to avoid it?
Add
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
to each activity you need.
I want to block my application orientation to portrait, but still receive orientation changes events. So I've tried to add the android:screenOrientation="portrait" attribute for blocking the orientation and the android:configChanges="keyboardHidden|orientation" attribute for receiving the orientation changes events in the ovverriden method onConfigurationChanged. Still the method doesn't get called. Is there a way to achieve this?
By forcing the orientation of your activity to portrait mode, you're not able to receive orientation changes.
Check Manifest.xml file. It should be like as below:
<activity android:name="YourActivity1"
android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"
android:configChanges="orientation|keyboardHidden"></activity>
<activity android:name="YourActivity2"
android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"
android:configChanges="orientation|keyboardHidden"></activity>
are you sure you write this for main activity like
< activity android:screenOrientation="portrait"...
I have an activity which should always be displayed in Landscape mode. So i added android:screenOrientation="landscape".
But the problem is when I rotate the device by 180 degrees, the display is inverted. is there a way to handle this issue so that the screen elements are always shown correctly.?
Actually what you really want is to specify:
android:screenOrientation="sensorLandscape"
in your AndroidManifest.xml. This will listen to the sensor data while snapping between landscape and reverseLandscape.
Others have mentioned sensorLandscape...to do this programmatically in your activity (or a base activity), you can set your orientation to that:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
I'm doing it in onResume(). This will respect landscape and reverse landscape when you flip the device around 180 degrees in the middle of the activity, without having to use onConfigurationChanged().
This was helpful to me since for tablets I need landscape/landscape reverse only, and for phones I need portrait/portrait reverse only, and don't want to do two separate AndroidManifest files. ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT also exists.
So just for everyone information, this is what i did.
In Android manifest added android:screenOrientation="landscape".
In on resume method add these lines of code
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();
if(orientation==Surface.ROTATION_180)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
This way my screen is always positioned correctly even if user holds the device upside down.
In the Android Manifest write this:
android:configChanges="orientation"
android:screenOrientation="landscape"
like in the example below.
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The good method is to use
setRequestedOrientation(6);
6 is the value for sensorLandscape but it seem's that there is no defined constant for it.
Hmmm. This depends a bit on the framework version you're using as well. Try this ast a start:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
If that works great. If it dosen't you have to tell us a little more about the layout of your app.