码迷,mamicode.com
首页 > 其他好文 > 详细

SwipeBackActivity 的使用

时间:2016-01-14 15:35:11      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

1、SwipeBackLayout

项目地址:https://github.com/ikew0ng/SwipeBackLayout

 

 

2、用法

android studio 

 

compile ‘me.imid.swipebacklayout.lib:library:1.0.0‘

 

 

项目实例

package com.example.yiba8.myapplication;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class BackActivity extends SwipeBackActivity {

    private TextView back ;
    private SwipeBackLayout mSwipeBackLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_back);

        mSwipeBackLayout = getSwipeBackLayout();

        int flag1 =   SwipeBackLayout.EDGE_LEFT ;   //左滑
        int flag2 =   SwipeBackLayout.EDGE_RIGHT ;  //右滑
        int flag3 =   SwipeBackLayout.EDGE_BOTTOM ; //下滑
        int flag4 =   SwipeBackLayout.EDGE_ALL ;    //全部

        //设置滑动模式
        mSwipeBackLayout.setEdgeTrackingEnabled(flag4);

        //自动调用滑动模式
        back = (TextView) findViewById( R.id.back );
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                scrollToFinishActivity();
            }
        });

        //设置是否可以滑动
        mSwipeBackLayout.setEnableGesture(true);

        //获取屏幕的宽度
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int  phoneWidth  = dm.widthPixels ;

        //设置侧滑的区域为屏幕宽度的1/3,如果不设置系统默认为50dip
        mSwipeBackLayout.setEdgeSize( phoneWidth / 3  );
    }
}

 

3、常见的问题

3.1 滑动后背景显示为黑屏

       技术分享

 

解决方法:在需要侧滑的 Activity 添加一个 Theme

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppBackTheme"  parent="@style/AppTheme">
        <item name="android:windowIsTranslucent">true</item>
    </style>

 

对activity添加theme

       <!--  侧滑返回  -->
        <activity
            android:theme="@style/AppBackTheme"
            android:name=".BackActivity">
        </activity>

 

SwipeBackActivity 的使用

标签:

原文地址:http://www.cnblogs.com/zhaoyanjun/p/5130183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!