Activity slide animation only works when back button is pressed
Im trying to add a sliding animation when entering and exiting an activity but it only works when the phones back button is pressed. When pressing the up button in the toolbar or a separate button it doesn't work.
I tried adding the overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
line to the onPause()
method as well as the finish()
method and the buttons OnClick method but it doesn't work :/
no_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="0"
android:fromXDelta="0"
android:toXDelta="0" />
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
Java:
public void button(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
public void finish(){
super.finish();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
android animation overridependingtransition
add a comment |
Im trying to add a sliding animation when entering and exiting an activity but it only works when the phones back button is pressed. When pressing the up button in the toolbar or a separate button it doesn't work.
I tried adding the overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
line to the onPause()
method as well as the finish()
method and the buttons OnClick method but it doesn't work :/
no_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="0"
android:fromXDelta="0"
android:toXDelta="0" />
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
Java:
public void button(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
public void finish(){
super.finish();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
android animation overridependingtransition
Usetoolbar.setNavigationOnClickListener();
as suggested in my answer!
– Gourav
Jan 1 at 15:53
add a comment |
Im trying to add a sliding animation when entering and exiting an activity but it only works when the phones back button is pressed. When pressing the up button in the toolbar or a separate button it doesn't work.
I tried adding the overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
line to the onPause()
method as well as the finish()
method and the buttons OnClick method but it doesn't work :/
no_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="0"
android:fromXDelta="0"
android:toXDelta="0" />
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
Java:
public void button(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
public void finish(){
super.finish();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
android animation overridependingtransition
Im trying to add a sliding animation when entering and exiting an activity but it only works when the phones back button is pressed. When pressing the up button in the toolbar or a separate button it doesn't work.
I tried adding the overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
line to the onPause()
method as well as the finish()
method and the buttons OnClick method but it doesn't work :/
no_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="0"
android:fromXDelta="0"
android:toXDelta="0" />
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
Java:
public void button(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
public void finish(){
super.finish();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.no_anim, R.anim.slide_out_right);
}
android animation overridependingtransition
android animation overridependingtransition
asked Jan 1 at 14:56
Pepe SilviaPepe Silvia
4116
4116
Usetoolbar.setNavigationOnClickListener();
as suggested in my answer!
– Gourav
Jan 1 at 15:53
add a comment |
Usetoolbar.setNavigationOnClickListener();
as suggested in my answer!
– Gourav
Jan 1 at 15:53
Use
toolbar.setNavigationOnClickListener();
as suggested in my answer!– Gourav
Jan 1 at 15:53
Use
toolbar.setNavigationOnClickListener();
as suggested in my answer!– Gourav
Jan 1 at 15:53
add a comment |
2 Answers
2
active
oldest
votes
You can call onBackPressed()
when pressing the up button in the toolbar
This is not regarded as a good approach!onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with itstoolbar.setNavigationOnClickListener()
?
– Gourav
Jan 1 at 15:55
add a comment |
Set toolbar Navigation click listener:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //close activity
overridePendingTransition(R.anim.your_anim, R.anim.your_anim);
}
});
This will surely work!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996461%2factivity-slide-animation-only-works-when-back-button-is-pressed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can call onBackPressed()
when pressing the up button in the toolbar
This is not regarded as a good approach!onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with itstoolbar.setNavigationOnClickListener()
?
– Gourav
Jan 1 at 15:55
add a comment |
You can call onBackPressed()
when pressing the up button in the toolbar
This is not regarded as a good approach!onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with itstoolbar.setNavigationOnClickListener()
?
– Gourav
Jan 1 at 15:55
add a comment |
You can call onBackPressed()
when pressing the up button in the toolbar
You can call onBackPressed()
when pressing the up button in the toolbar
answered Jan 1 at 15:02
Saurav GhimireSaurav Ghimire
341113
341113
This is not regarded as a good approach!onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with itstoolbar.setNavigationOnClickListener()
?
– Gourav
Jan 1 at 15:55
add a comment |
This is not regarded as a good approach!onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with itstoolbar.setNavigationOnClickListener()
?
– Gourav
Jan 1 at 15:55
This is not regarded as a good approach!
onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with its toolbar.setNavigationOnClickListener()
?– Gourav
Jan 1 at 15:55
This is not regarded as a good approach!
onBackPressed()
should be called when we want to handle default back button clicks in android! If android wished to do so, why they would have added the facility to provide back click facility on toolbar with its toolbar.setNavigationOnClickListener()
?– Gourav
Jan 1 at 15:55
add a comment |
Set toolbar Navigation click listener:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //close activity
overridePendingTransition(R.anim.your_anim, R.anim.your_anim);
}
});
This will surely work!
add a comment |
Set toolbar Navigation click listener:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //close activity
overridePendingTransition(R.anim.your_anim, R.anim.your_anim);
}
});
This will surely work!
add a comment |
Set toolbar Navigation click listener:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //close activity
overridePendingTransition(R.anim.your_anim, R.anim.your_anim);
}
});
This will surely work!
Set toolbar Navigation click listener:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //close activity
overridePendingTransition(R.anim.your_anim, R.anim.your_anim);
}
});
This will surely work!
answered Jan 1 at 15:47
GouravGourav
7391629
7391629
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996461%2factivity-slide-animation-only-works-when-back-button-is-pressed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use
toolbar.setNavigationOnClickListener();
as suggested in my answer!– Gourav
Jan 1 at 15:53