When I was browsing the slack application I found new feature I liked, which is the return of activity by dragging without pressing the back button as usual.
So is there a specific code to do that? I did a research on how to do that but I couldn't find any explanation for it, so how can I do that.
Here is a short video about the new feature click here
1- We will use a library to do that called Slidr , use the last version.
// swipe the Activity to close
implementation 'com.r0adkll:slidableactivity:2.1.0'
2- Add a new style in your styles.xml
called SliderActivityTheme . This theme will make the background for the activity when swipe it as transparent to show the content of the fragment...etc, "default background white"
<!--Theme for Slider Activity-->
<style name="AppTheme.SliderActivityTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
3- A- Add slide method to your class
and called in OnCreate
// Make slider on the Activity
public void Slider () {
Slidr.attach(this);
}
B- Called in OnCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_name_here);
// slider the activity
Slider();
}
or just simply add this in your OnCreate
directly
// slider the activity
Slidr.attach(this);
4- In your AndroidManifest.xml
add the theme that we had to create.
android:theme="@style/AppTheme.SliderActivityTheme"
Make it like that
<activity
android:name=".Activity.ActivityImages.ImagesMorningActivity"
android:launchMode="singleTop"
android:theme="@style/AppTheme.SliderActivityTheme"/>
<activity
That's all, and enjoy with your new feature;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.