Android仿微信activity滑动关闭效果
Android仿微信activity滑动关闭功能
1.利用具体利用v4包下的slidingPaneLayout实现透明的activity,代码如下:
BaseActivity: publicclassBaseSlideCloseActivityextendsAppCompatActivityimplements SlidingPaneLayout.PanelSlideListener{ @Override protectedvoidonCreate(BundlesavedInstanceState){ initSlideBackClose(); super.onCreate(savedInstanceState); } privatevoidinitSlideBackClose(){ if(isSupportSwipeBack()){ SlidingPaneLayoutslidingPaneLayout=newSlidingPaneLayout(this); //通过反射改变mOverhangSize的值为0, //这个mOverhangSize值为菜单到右边屏幕的最短距离, //默认是32dp,现在给它改成0 try{ FieldoverhangSize=SlidingPaneLayout.class.getDeclaredField("mOverhangSize"); overhangSize.setAccessible(true); overhangSize.set(slidingPaneLayout,0); }catch(Exceptione){ e.printStackTrace(); } slidingPaneLayout.setPanelSlideListener(this); slidingPaneLayout.setSliderFadeColor(getResources() .getColor(android.R.color.transparent)); //左侧的透明视图 ViewleftView=newView(this); leftView.setLayoutParams(newViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); slidingPaneLayout.addView(leftView,0); ViewGroupdecorView=(ViewGroup)getWindow().getDecorView(); //右侧的内容视图 ViewGroupdecorChild=(ViewGroup)decorView.getChildAt(0); decorChild.setBackgroundColor(getResources() .getColor(android.R.color.white)); decorView.removeView(decorChild); decorView.addView(slidingPaneLayout); //为SlidingPaneLayout添加内容视图 slidingPaneLayout.addView(decorChild,1); } } protectedbooleanisSupportSwipeBack(){ returntrue; } @Override publicvoidonPanelSlide(Viewpanel,floatslideOffset){ } @Override publicvoidonPanelOpened(Viewpanel){ finish(); } @Override publicvoidonPanelClosed(Viewpanel){ } }
activity透明style:
<resourcesxmlns:tools="http://schemas.android.com/tools"> <!--Baseapplicationtheme.--> <stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"> <!--Customizeyourthemehere.--> <itemname="colorPrimary">@color/colorPrimary</item> <itemname="colorPrimaryDark">@color/colorPrimaryDark</item> <itemname="colorAccent">@color/colorAccent</item> </style> <stylename="DIY.SlideClose.Transparent.Theme"parent="AppTheme"> <itemname="android:windowBackground">@android:color/transparent</item> <itemname="android:windowIsTranslucent">true</item> <itemname="android:windowAnimationStyle">@style/DIY.Animation.SlidingBack</item> <itemname="android:actionBarStyle">@style/DIYActionBar.Custom</item> </style> <stylename="DIYActionBar.Custom"parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <itemname="displayOptions">showCustom</item> <itemname="android:background">@android:color/transparent</item> <itemname="background">@android:color/transparent</item> <itemname="android:displayOptions"tools:ignore="NewApi">showCustom</item> <itemname="android:height">?actionBarSize</item> </style> <stylename="DIY.Animation.SlidingBack"parent="@android:style/Animation.Activity"> <itemname="android:activityOpenEnterAnimation">@anim/slide_in_right</item> <itemname="android:activityOpenExitAnimation">@anim/slide_out_right</item> <itemname="android:activityCloseEnterAnimation">@anim/slide_in_right</item> <itemname="android:activityCloseExitAnimation">@anim/slide_out_right</item> <itemname="android:wallpaperOpenEnterAnimation">@anim/slide_in_right</item> <itemname="android:wallpaperOpenExitAnimation">@anim/slide_out_right</item> <itemname="android:wallpaperCloseEnterAnimation">@anim/slide_in_right</item> <itemname="android:wallpaperCloseExitAnimation">@anim/slide_out_right</item> <itemname="android:wallpaperIntraOpenEnterAnimation">@anim/slide_in_right</item> <itemname="android:wallpaperIntraOpenExitAnimation">@anim/slide_out_right</item> <itemname="android:wallpaperIntraCloseEnterAnimation">@anim/slide_in_right</item> <itemname="android:wallpaperIntraCloseExitAnimation">@anim/slide_out_right</item> </style> </resources>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。