Smoother transition from fullscreen activity using ActionBarSherlock - android

I'm developing an Android application which uses ActionBarSherlock (ABS) and needs to work in API >=8. The problem is that some transitions between activities aren't smooth enough.
For example: I have two activities, (A) one which is always fullscreen and (B) another one which isn't fullscreen (status bar and action bar are shown). The transition needed is always from A to B. When it occurs and B activity is loaded, all the content (included ABS) is shown as if the activity was fullscreen and then resizes when the status bar is loaded again.
In some devices this effect is insignificant but in other ones it becomes really annoying and even causes that the user touches the wrong section of the view.
Fullscreen declaration is made via Manifest activity's "theme" property (anything by code). For example:
<activity
android:name = "...."
android:screenOrientation = "portrait"
android:theme = "#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Searching on the Internet for some solution, I've found two main approaches:
1) To use the Android appcompat library and enabling action bar overlay as mentioned here: https://developer.android.com/training/basics/actionbar/overlaying.html#EnableOverlay.
The problem with this is that the app also uses the HoloEverywhere library and many errors appeared when using HoloEverywhere + appcompat. All this errors were related to duplicated XML elements. I've also checked android-support-v4 library in all projects to avoid errors.
2) Using WindowManager flags and applying top padding to the view: http://nubinewsblog.blogspot.com.es/2009/11/smooth-full-screen-transition.html.
With this approach the transition is perfect. The biggest problem - and the reason I need to ask this - is that I'm not able to apply a top margin to ABS and the status bar is shown over the action bar. I can move down all elements except ABS. I suppose it occurs because ABS uses many fixed dimensions and attributes.
I prefer to use the second way (2) but I can try everything needed to make the transition smoother. Any further implementation details needed can be asked and I'll try to answer ASAP. I'd be very grateful for any info or help provided :-)
Really thanks to all for your time.
PS: I'm currently using and Android 2.3.6 device for testing.
PS: when I say fullscreen I always refer to fullscreen + no status bar + no action bar.

I've solved my problem doing the following:
1.- I have to optimize all the screens where the AB was shown. In some cases I used ListViews which weren't correctly implemented and that caused a noticeable load time in the activity.
2.- I have shown the status bar BEFORE starting the new activity. I mean: I've shown the status bar in the fullscreen activity just before starting the non-fullscreen one. With that I achieved that the layout of the second activity (non-fullscreen) was never resized.
With this two little changes now the AB transition is much more smoother.
I close this question but, if someone has any doubt, I will be pleased to answer it. Last but not least, ¡thanks to all who tried to help with this problem!

the best solution is to clear full screen flags on onPause method of first (full screen) activity
#Override
protected void onPause(){
super.onPause();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Related

Is there a way to set up an app bar/action bar in an Android app without going through the appcompat library?

I'm having a "this can't be right moment" trying to learn Android app development. I want to add some buttons to the top bar (app bar, toolbar, action bar, etc) of my Activity. Apparently this thing is called the app bar. But when I read the docs, I feel like I'm taking crazy pills:
This class describes how to use the v7 appcompat support library's Toolbar widget as an app bar.
Why do I have to use something called "appcompat" to add a toolbar? I don't care about backwards compatibility right now, I'm just coding an app to learn. Normally backwards compatibility shims/layers are an optional thing. I just want to do this in the most straightforward way at the moment - it'll be easier for me to learn that way.
There are other ways to implement an app bar—for example, some themes set up an ActionBar as an app bar by default—but using the appcompat Toolbar makes it easy to set up an app bar that works on the widest range of devices, and also gives you room to customize your app bar later on as your app develops.
Again, this sounds like the docs are saying that the method they advocate is not the simplest and most basic way, and that there's another. Then one of the very first steps in the tutorial is:
In the app manifest, set the element to use one of appcompat's NoActionBar themes. Using one of these themes prevents the app from using the native ActionBar class to provide the app bar.
Huh? So the first step to getting a toolbar is to turn off the toolbar? At this point I feel like I can hear clown horns going off. Am I being pranked? I don't think Google realize how bonkers this all sounds to a complete beginner.
Is there a way to add buttons/actions to the default Material UI ActionBar in an Activity, without going through the appcompat package?

How to get a seamless transition from app bar to status bar

So I'm currently trying to migrate an app to use Material 3 consistently. Previously it was stiched together without any real design concept. Now I want to actually look like something to take serious.
One thing I haven't been able to figure out is how to give the status bar the same color as the title bar. Currently it looks like this:
The official documentation however lists the seamless version in the "What's new" section:
I'm currently using a LinearLayout with the Theme.Material3.DayNight theme (without any modifications for now) and from what I was able to learn from the documentation I need to make use of components like MaterialToolbar inside a AppBarLayout inside a CoordinatorLayout so everything works as intended. I tried doing that and the scrolling and lifting now works as described in the documentation, but the color of the status bar remains unchanged unfortunately.
I'm not sure at this point if my expectations are wrong or if my code is. I believe that there has to be a built-in mechanism that automatically adjusts the status bar's colour to dynamically match the one of the app bar. I might be wrong though and the material-components-android expects me to implement the logic myself. In any case, could someone point me towards an example implementation where this transition is seamless? This way I could modify my code to implement this behaviour.
I'm currently using com.google.android.material:material:1.5.0 in case this is relevant to the problem.
Thanks in advance!

Transition when theme switching (or Activity.recreate())

I'm targeting API level 14+, so I've used Activity.recreate() for theme switching in my app. It worked out nice, except a black screen will flash for about 0.5s.
I used to think it is impossible to provide a better experience here, until I saw a material designed app which successfully switched its theme with a crossfade. But unluckily I failed to recall its name since I uninstalled it from my phone some time ago.
I've tried Activity.overridePendingTransition(), it did not work, and I believe the reason is that the recreate() call is much like a configuration change so the mechanism is different from finishing and launching a brand new activity.
(And while trying to find that app I came across another magic theme switching app, even without calling recreate(). Hum... Anybody know how the trick is done?)
Theme switching on the fly GIF
Who said themes were immutable? Changing the primary and accent colors on…
EDIT:
I found that the GIF above is kind of a distraction from the original question, so I turned it into a link.
My original question is that, is there any method to change (switch) theme with an appropriate transition?
Changing all the things on screen by Brute force is not switching the app's theme; it just appear to be though, but it can lead to many problems.
Sad to find out the above GIF may only be a hacky brute force attack, but still thanks to #Emanuel Moecklin for pointing this out.
But I still hope a "(truly) switching theme with transition" solution can come up, or someone tell me that Activity.recreate() cannot be animated and no other ways can switch themes better.
After all these years I've learned an easy way.
Instead of Activity.recreate(), use the follwing code fragment:
finish();
startActivity(new Intent(this, getClass()));
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
And it will give you a nice animation between themes.
Bonus: You can manually save & restore instance state to preserve UI state, and ignore user input during restarting by overriding input related methods (dispatch*Event()) on Activity.
Check out this answer to a similar question:
https://stackoverflow.com/a/26511725/534471
What the app you mention in your question does, isn't changing the theme but changing the color of the status bar, the action bar and the navigation bar:
Status Bar:
getWindow().setStatusBarColor(colorStatus);
Action Bar:
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable( new ColorDrawable( colorAction ) );
Navigation Bar:
getWindow().setNavigationBarColor(colorStatus);
My guess is that the accent color is changed by just setting the background color of the two visible elements (the floating action button and the tab navigation). Tab navigation colors can be changed like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setStackedBackgroundDrawable( new ColorDrawable( accentColor ) );

Make ActionBar overlay using ActionBarSherlock

The last few days I've been doing great stuff in development, but I've seem to have hit a wall on something probably stupid simple. It's annoying. I was hoping I could get some help.
What I'm trying to do
I'm trying to create the awesome transparent ActionBar animation effect from Google Music (as described by Cyril Mottier here)
The problem
I can't even get the actionbar to go into overlay / transparent mode.
My set-up
I've got a library-oriented set-up in Eclipse. I've got a library project (let's call it master) that contains all the actual code and activities. Then I've got a project, that just plugs into the master library (let's call it slave). Lastly there's some open source support libraries that master uses (among others is ActionBarSherlock).
The activity I'm trying to apply this effect to is in the master library. It is declared in slave's manifest as com.example.master.DetailActivity, and that works like a charm.
Also: The theme for the activity may come from several places. Either it's set by slave's manifest, or by master at runtime. Themes may come from the master OR the slave project.
What I've tried
Feels like everything. I've started out by creating a custom theme based on Cyril's article. I made sure that for every item I've had a version with and without the android: prefix as per Jake Wharton's instructions.
I've also tried setting it at runtime using requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
What I've got
Nothing. The theme applied succesfully (I can see the actionbar's colors change appropriately), but it NEVER goes into overlay mode, nor does it become transparent.
Help would be greatly appreciated, and would probably be helpful to other's trying this effect.
EDIT:
Here are my themes and styles. Codes are kinda messy because I've been experimenting with them to see where I was going wrong. AppTheme and Theme.TranslucentActionBar.ActionBar.Overlay both won't work.
/res/values/
styles.xml
themes.xml
/res/values-v11/
styles.xml
themes.xml
I'm testing on a Nexus 4 with 4.2.2 installed as well as a 2.3.3 emulator.
OK, so apparently, with my set-up, you can't do it using themes.
I ended it up doing it, globally like this.
setTheme(theme.whatever);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.color)); // This is #212121 solid color for the dark action bar.
The lines are spread out over my code, but this is the gist of it. The order is important.
I also found out that sliding menu seemed to be blocking the overlay mode. I had to remove the instance for it to work. I'm still looking for a way to enable both overlay mode and the sliding menu.

Android Navigation Bar

I've done a great amount of searching and I can't seem to find anything that helps me. I'm new to Android programming (I do know Java though), and I am working on an app that deals with dynamic content being downloaded from a server. I would like to have a bottom navigation bar, that is persistent throughout the app. This nav bar will consist of 5 buttons, that when clicked will open a new activity. However I would like the activity to be loaded in the content area above the nav bar.
So basically I will have a layout that contains a content view and the nav controller. The nav controller should never change...the content view should load a new activity upon nav button click. Does anyone have any ideas? Thanks.
You will have to create a common layout for the navigation bar , and include it in every layout of the activity. use "include" tag in the xml to do this. please have a look at the discussion below, it may help you.
Common buttons or tabs at bottom for every activity
Have a look at this project: http://code.google.com/p/androidtabs/
You might want to consider looking at Fragments since the TabActivity is deprecated. You would need to download a compatibility package in the SDK in order to use it on pre-honeycomb devices. It should be able to do exactly as you want.

Categories

Resources