How to change orientation using a menu button? - java

I would like to handle the orientation change of my app with a menu button, so it doesn't change views when the device is turned, but when the user presses a menu item. Can you tell me the best way to do this? Everything that comes to my mind seems to be stupid.
Thanks a lot!

You can call setRequestedOrientation so specify an orientation.
In your xml-Manifest file you can specify a android:screenOrientation="portrait" to not change the orientation automatically.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Related

Is there any way to disable android default pop up layout and show a custom layout instead?

I want to change android default volume layout and show a custom animations instead. Is there any feasible solution or any other approach?
sample image here!
nope, there is no option for such change
BUT using AccessibilityService you may catch volume button clicks and then draw on screen when SYSTEM_ALERT_WINDOW permission is granted. thats pretty hard task

android Change orientation removing button

I've set android:configChanges="orientation|screenSize" on an activity to stop it restarting the activity everytime the orientation changes. Now this works fine but I think it's stopping the correct layouts from being used.
E.G. I have different layout folders for different orientations and sizes of screen. So if I start the activity in portrait, when I change the orientation to landscape, it's not using my landscape layout.
Also if I start the activity in landscape, when I change the orientation to portrait, it's not using my portrait layout.
Basically what I want the app to do is not start the activity again once the orientation changes, but use the correct layout when the orientation is changed!
I was thinking I could use the onConfigurationChanged method to explicitly change the layout in code?
Thanks for any input
when you use android:configChanges="orientation|screenSize" this tells to Android that you will maintain these changes by yourself - this means you have to change your layout (setContentView) and initialize it manually (set values of controls - EditTexts, Spinners etc.)
So What I've ended up doing is keeping android:configChanges="orientation|screenSize" in the manifest file. Doing it this way stops me being able to use my correct layout folders for portrait and landscape.
To overcome this issue, I override the onConfigurationChange method to set the correct information I needed for the activity to run as expected once the orientation changes. below is the code I've used:
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
setContentView(R.layout.hearing_test);
//Any other information needed for the activity to work correctly
}
Thanks for the help and guidance #mihail, helped me get to the bottom of the issue.
That is exactly why the Activity is destroyed and recreated: to apply new resources.
Do not use android:configChanges="orientation" if you have different layouts for portrait and landscape mode.

Change orientation without setRequestedOrientation

When I click a button in my App, the screen orientation will automatically go to landscape :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
The screen get to landscape successfully but it caused my onConfigurationChanged not working anymore.
I tried to use: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); but it makes no difference.
What should I do, to make the screen go to landscape, when I click the button, without turning off the onConfigurationChanged?Or do you have any other ways to accomplish this?
If you are using API13 or higher as your target,
in your manifest you need to add ScreenSize to your configChanges:
android:configChanges="orientation|screenSize|keyboardHidden"
That should do the trick!

How can an app temporarily display a full screen animation in an Android activity?

Similar questions have been asked before, but I couldn't find an answer to how to make one element full screen. I would like to temporarily display a full-screen animation in my Android app without moving to a new Activity. The app has an ImageView for the animation and I show the animation with:
image.setBackground(animation);
and make it "go away" with:
image.setBackground(null);
For the ImageView, both android:layout_width and android:layout_height are set to "match_parent". It works, but of course the animation doesn't include the title bar at the top or the icons at the bottom. I even tried setting the layout_marginTop and layout_marginBottom to negative values, but I know that can't be the best solution for every device or orientation which may run this app.
How can I change the size of the ImageView to full screen so I can show it as needed, or is there a better way to do what I want?
Duplicate of Fullscreen Activity in Android?.
Just set the right flags and dismiss the activity when it's finished its animation.
Your ImageView is stuck inside the bounds of your Activity. And I don't think there is a way for you to change your Activity to be full screen sometimes but not others.
If you want your Activity to be fullscreen always you can set the theme in the manifest like this:
<activity
android:name="com.your.package.name.YourActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Combine both answers. Create a new activity to play your animation and set the theme of your animation activity to fullscreen.

android Window Soft Input Mode

In my app, I need to use EditText. But i have a problem with it. On some firmwares (Ice cream sandwich for example) when user click on edittext, keyboard pushes whole screen up! I want to turn it off.
I tried to add android:windowSoftInputMode="adjustResize". Nothing changed.
Help me please.
try
android:windowSoftInputMode="adjustPan"
That perfect work for you.
Add this in your AndroidManifest.xml
android:windowSoftInputMode="stateHidden"
Perfectly works for me. You try this one.

Categories

Resources