I want my Android application to behave like below.
1) Portrait mode: With title bar
2) Landscape mode: Without title bar (because of height limitation)
I know I can realize 1) using requestWindowFeature(Window.FEATURE_NO_TITLE), but
how can I dynamically change from 1) to 2) when I rotate my phone?
When the phone is rotated, your activity is shut down and recreated. Inside onCreate, you can grab an instance of Display (using getWindowManager().getDefaultDisplay()) and query its width, height, and/or rotation to decide if you want a title feature, all before setting the content view.
This answer suggests you can't change the feature during the lifecycle of the activity (as happens when the orientation changes), so they recommend implementing your own title (jump to the "::Edit::" part):
Hiding Title in a Fullscreen mode?
::Edit::
Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called.
One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track
Since when you change orientation, your app goes through a set of lifecycle changes, you have an opportunity in onCreate to show or hide your title.
http://stuffthathappens.com/blog/2008/11/26/android-lifecycle-triggers-part-2/
Or you specify a different layout altogether for landscape mode:
http://developer.android.com/resources/tutorials/hello-world.html
Landscape layout
When you want a different design for landscape, put your layout XML file inside /res/layout-land. Android will automatically look here when the layout changes. Without this special landscape layout defined, Android will stretch the default layout.
Related
I'm trying to look for any Android Element or Window which will stay on top of the app and will not be removed when changing activities.
Android's banner seems to be per activity.
PopupWindow as well.
I can't change the app's activities - cannot change them into fragments.
Is this possible?
When the soft keyboard shows up, I only want the Views inside the most outer layout to be pushed up. The reason is because the most outer layout has a background which gets squished when the keyboard shows up. I want the background to be unaffected.
How do I do this?
I had the same issue when developing a chat app. What worked for me was setting the background on the window and not in the layout. Like this:
getActivity().getWindow().setBackgroundDrawableResource(R.drawable.background_hd);
Have you tried setting the following:
android:windowSoftInputMode="adjustResize"
in the <activity../> tag in AndroidManifest?
This should adjust the size of your layout in this activity when the keyboard is displayed.
There are plenty of more implementations you can use to handle different states RE the documentation:
http://developer.android.com/guide/topics/manifest/activity-element.html
I wonder and not getting how facebook manages to fit the layout on all screen sizes by removing the padding or margins as shown below in landscape mode and open keyboard mode.
If anyone has implemented the same or getting the logic behind it please let me know.
If you place the elements inside a ScrollView, they will automatically move up when the keyboard is open. You must also have android:windowSoftInputMode="adjustResize" in your AndroidManifest.xml file for the appropriate Activity.
I'd been trying to maintain consistency in layout whether keyboard is open or not. These issue is generated in FULLSCREEN Mode (hiding top notification bar) only. It works like a charm without Fullscreen.
Tried:
Added android:softWindowMode="adjustResize" and android:softWindowMode="adjustPan"inside <activity> of Manifest File.
Added android:isScrollableContainer="false" inside by top layout with blue background having first, next,prev,last symbol.
Desired Layout:
Top Layout Blue Background should never get hide whether keyboard is open or not.
These issue get resolved with ActionBar but it requires a lot of turn work which I don't intent to.
.
Is there any way other than ActionBar which resolve my issue?
Try to create a fixed header layout for the blue back ground layout, and below this blue layout create a layout for other fields inside the ScrollView ...so that when keyboard appeared it will not hide the header blue layout...
The Android app Thrutu puts a drawer on top of the in call screen which has several functions and only takes up a fraction of the screen. The call control buttons below still are fully functional. Even a transparent activity would not allow this behaviour. Any idea on how to implement this?
The trick to making the underlying buttons work is to implement the UI using a Service rather than an Activity, make the Window you add (using WindowManager.addView) one of the higher-priority types (e.g. TYPE_PHONE), then use FLAG_NOT_TOUCH_MODAL.
I think you need android.permission.SYSTEM_ALERT_WINDOW.
Take a look at How to display a fullscreen TYPE_SYSTEM_ALERT window? and in particular Creating a system overlay where the home buttons still work?