android:#Theme.Translucent Locks orientation to Portrait? - android

I've created a new style to set the background as transparent, but for some reason ever since the app doesn't change layout to landscape when device is rotated.
Should I specify something in the new style ?
Here is it's code :
< style name="Transparent" parent="android:#Theme.Translucent">
< item name="android:windowBackground">#color/background</item>
</style>

While you are not specify android:screenOrientation for activty, android uses
"unspecified" default value, which means that the system chooses the orientation.
In a case you are using style with <item name="android:windowIsTranslucent">true</item>, system selects an orientation based on the orientation of underlying activity in stack. So it's hard to get your application in landscape mode, because most of launchers fixed to portrait.
Just set android:screenOrientation="sensor" for all Translucent activities to force it choose orientation independently:
<activity
android:name=".SomeActivity"
android:screenOrientation="sensor"
...>
...
</activity>

I actually kinda solved it apparently the orientation is according to the background app in case of transparent background, since i kept testing when the Launcher in the back, i always got portrait only.

just right in manifest
<activity
android:name=".Ippin_NewActivity"
android:configChanges="keyboardHidden|orientation"
android:label="#string/app_name" >
</activity>

Related

How to set the Portrait and landscape orientation in android manifest file

Portrait mode is working and landscape is not showing.
android:screenOrientation="portrait" // Here i need to show both portrait and landscape.
You can use:
android:screenOrientation="unspecified"
This is the default value and the system chooses the orientation.
alternatively, you can use:
android:screenOrientation="fullSensor"
In this case, device orientation sensor determinates the screen orientation.
Try one and the other to see which one works best for you.
EDIT:
For a specific class, you can do this:
<activity
android:name=".YOUR_CLASS"
android:screenOrientation="unspecified" // or what you want
android:theme="#style/Theme.Design.NoActionBar"/>

How to change the app name which is placed in the launcher screen

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)

Button background color is changed by portrait to landscape mode

I am new to Android Application development. In my application if I click on button,it changes it background color from black to green.
If I change the mode from portrait to landscape then it changes the color from green to black with out click on button.
My requirement is,have to stop background color change,by changing the mode from portrait to landscape or landscape to portrait.
Please help me to go forward.
When screen orientation changes, the method onCreate() is called.
My guess is you are calling Button.setBackgroundColor() in this onCreate() method...
Try surrounding this call with if(savedInstanceBundle == null){}, like that it will only set the color to black on the first onCreate() call, and not for any subsequent calls.
Use android:configChanges="orientation" in your activity declaration in manifest. Like this
<activity android:name=".MyActivity"
android:configChanges="orientation"
android:label="#string/app_name">
When you rotate device then onCreate() method calls again to avoid this use below code
android:configChanges="orientation"
in the Manifest.xml for activity
<activity
android:name="com.sample.stackoverflow.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name" />
If you want to load specific layout when orientation change :
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// use your setcontentView here
}

The theme in manifest.xml

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.

How to keep the screen in landscape mode in Android

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.

Categories

Resources