I'm currently trying to use the new transition animations in Android 5.0.
I started as suggested by many Tutorials:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setEnterTransition(new Explode());
getWindow().setExitTransition(new Explode());
setContentView(R.layout.activity_quiz);
getActionBar().setTitle("Java Skill");
getActionBar().setElevation(2);
}
I put this code into every activity of my project but it never works. The only animation I get is the "slide in effect" from the bottom.
Am I doing something wrong here? Do I have to define anything else, maybe in my layouts or styles.xml?
I hope anyone ran into the same problem as me. Thanks very much in advance!
The documentation may be wrong. You need to enable FEATURE_ACTIVITY_TRANSITION.
Related
How do I force the screen to stay active and not shut off while my app is running?
PLEASE DO NOT USE A WAKE LOCK
This requires that you give your app an additional permission, and it is very easy to introduce bugs where you accidentally remain holding the wake lock and thus leave the screen on.
It is far, far better to use the window flag FLAG_KEEP_SCREEN_ON, which you can enable on your activity's window in your onCreate() like this:
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
This will make sure that the screen stays on while your window is in the foreground, and only while it is in the foreground. It greatly simplifies this common use case, eliminating any juggling you need to do as your app transitions between states.
This Question has Already Great Answer by #hackbod !
I am Answering this Question with Two Additional Solutions !
Existing Solution :
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Additional Solutions:
we can use keepScreenOn
1. implementation using setKeepScreenOn() in java code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// or any View (in case generated programmatically )
View v = getLayoutInflater().inflate(R.layout.driver_home, null);
v.setKeepScreenOn(true);
setContentView(v);
}
Docs http://developer.android.com/reference/android/view/View.html#setKeepScreenOn(boolean)
2. Adding keepScreenOn to xml layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" >
Docs http://developer.android.com/reference/android/view/View.html#attr_android%3akeepScreenOn
Note ( Some Useful Points) :
1. it Doesn't matter that keepScreenOn should be used on Main/Root/Parent View it can be used with any child view will work As same as it works in Parent view
2. The Thing Only matter is that View's Visibility must be visible other wise it will not work !
Another solution is to add android:keepScreenOn="true" (documentation) to the views that need to keep the screen on.
Allows for a little bit more granular control in terms of which views stay on and which don't. You can even reference a setting from a resource file this way.
I just worked through the first introductory application for Android programming and noticed some strange behavior:
When the second Activity was generated it received the line:
getActionBar().setDisplayHomeAsUpEnabled(true);
in the onCreate function. As the tutorial points out, this line requires at least API level 11 and a guard for that and #SuppressLint("NewApi") should be added like so:
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
The strange thing is that ignoring this advice and just hitting run worked fine at first but as soon as I made changes to the code it didn't work anymore and I got errors.
So when is lint actually active?
I am using API 10 GingerBread
I am not using a layout, although I did try this with a layout and it still doesn't work. Works fine with a normal Activity subclass, I don't see what the problem is.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.ic_launcher);
For what it is worth, using FEATURE_NO_TITLE works fine. What gives? Anybody have any suggestions?
Try this code...
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main); //or whatever layout is shows
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.ic_launcher);
I have this problem with the Android ActionBarCompat project: On emulators with Android 4.0 the click on the app icon doesn't cause any onOptionsItemSelected event, whereas it works on all other OS versions.
Any input is greatly appreciated!
Are you seeing any touch feedback from the app icon? (Does it glow when you press it?)
Since many activities do not use the action bar home button, in apps that target API 14+ running on Android 4.0 it is disabled by default. (This is so that users don't try pressing it, see it glow, and wonder why nothing happened.) Apps that want to use this should call ActionBar#setHomeButtonEnabled(true).
We should probably revise the ActionBarCompat sample to surface this more clearly. One simple way to get you up and running would be to modify ActionBarHelperICS.java and add the following:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity.getActionBar().setHomeButtonEnabled(true);
}
In an app where you want more control over turning this on and off you would want to make further changes.
I had this problem as well. This code did the trick for me:
public void onCreate(Bundle savedInstanceState) {
...
if (android.os.Build.VERSION.SDK_INT >= 11) {
//noinspection ConstantConditions
getActionBar().setHomeButtonEnabled(true);
} else {
getSupportActionBar().setHomeButtonEnabled(true);
}
}
Some extra info: minSdkVersion="7" targetSdkVersion="18". This is the LAUNCHER activity of my project, so it has no parent activity. Using setDisplayHomeAsUpEnabled(true) in other activities worked just fine.
Any one can share the mainfest.xml.
How to set it? then can remove the label..?
Thanks very much
Your question isn't very clear, but assuming you're asking about displaying the name of your application: There's a line in the < application > section that has "#string/app_name" in it, which you could remove. Not sure that's a good idea though. Alternatively you might be asking how to remove the title bar at the top of an application. If so, use
requestWindowFeature(Window.FEATURE_NO_TITLE);
If by removing the default label, you mean removing the title bar, you can use the following in your onCreate
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}