日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

用SwipeBackLayout让activity具有滑动返回的效果

發布時間:2024/4/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用SwipeBackLayout让activity具有滑动返回的效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目地址:
https://github.com/ikew0ng/SwipeBackLayout
一、讓需要滑動的Activity基礎自定義的style
這里就是為了解決滑動黑屏的問題

<style name="KaleTheme" parent="AppBaseTheme"><!-- 解決activity切換時的黑屏問題 --><item name="android:windowIsTranslucent">true</item> </style> styles.xml中的全部文件:
<resources><!--Base application theme, dependent on API level. This theme is replacedby AppBaseTheme from res/values-vXX/styles.xml on newer devices.--><style name="AppBaseTheme" parent="Theme.AppCompat.Light"><!--Theme customizations available in newer API levels can go inres/values-vXX/styles.xml, while customizations related tobackward-compatibility can go here.--></style><!-- Application theme. --><style name="AppTheme" parent="AppBaseTheme"><!-- All customizations that are NOT specific to a particular API-level can go here. --></style><style name="KaleTheme" parent="AppBaseTheme"><!-- 解決activity切換時的黑屏問題 --><item name="android:windowIsTranslucent">true</item> </style> </resources>我是直接用Application使用了這個樣式,僅僅為了演示。
<applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/KaleTheme" >
二、 用Activity繼承一個類

如果你是要兼容Actionbar那么就繼承SwipeBackActionbarActivity,這個類是我自己改的,原來的lib中沒有。如果不用兼容,那么直接用SwipeBackActivity即可。
三、在方法中找到SwipeBackLayout,并設置滑動的區域和方向

這個就是簡單的設置,我直接貼代碼了。

package com.kale.swipbacklayouttest; import me.imid.swipebacklayout.lib.SwipeBackLayout; import me.imid.swipebacklayout.lib.app.SwipeBackActionbarActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;/*** @author:Jack Tony* @tips :如果要兼容,那么繼承SwipeBackActionbarActivity,否則繼承SwipeBackActivity* @date :2014-10-31*/ public class MainActivity extends SwipeBackActionbarActivity {private SwipeBackLayout mSwipeBackLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mSwipeBackLayout = getSwipeBackLayout();//設置可以滑動的區域,推薦用屏幕像素的一半來指定mSwipeBackLayout.setEdgeSize(200);//設定滑動關閉的方向,SwipeBackLayout.EDGE_ALL表示向下、左、右滑動均可。EDGE_LEFT,EDGE_RIGHT,EDGE_BOTTOMmSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_ALL);Button btn = (Button)findViewById(R.id.open_button);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO 自動生成的方法存根startActivity(new Intent(MainActivity.this,MainActivity.class));}});}}上面還添加了一個button,是用來開啟新的Activity,主要是便于測試的。


總結

以上是生活随笔為你收集整理的用SwipeBackLayout让activity具有滑动返回的效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。