編輯:關於Android編程
Android仿微信activity滑動關閉功能
1.利用具體利用v4包下的slidingPaneLayout實現透明的activity,代碼如下:
BaseActivity: public class BaseSlideCloseActivity extends AppCompatActivity implements SlidingPaneLayout.PanelSlideListener { @Override protected void onCreate(Bundle savedInstanceState) { initSlideBackClose(); super.onCreate(savedInstanceState); } private void initSlideBackClose() { if (isSupportSwipeBack()) { SlidingPaneLayout slidingPaneLayout = new SlidingPaneLayout(this); // 通過反射改變mOverhangSize的值為0, // 這個mOverhangSize值為菜單到右邊屏幕的最短距離, // 默認是32dp,現在給它改成0 try { Field overhangSize = SlidingPaneLayout.class.getDeclaredField("mOverhangSize"); overhangSize.setAccessible(true); overhangSize.set(slidingPaneLayout, 0); } catch (Exception e) { e.printStackTrace(); } slidingPaneLayout.setPanelSlideListener(this); slidingPaneLayout.setSliderFadeColor(getResources() .getColor(android.R.color.transparent)); // 左側的透明視圖 View leftView = new View(this); leftView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); slidingPaneLayout.addView(leftView, 0); ViewGroup decorView = (ViewGroup) getWindow().getDecorView(); // 右側的內容視圖 ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0); decorChild.setBackgroundColor(getResources() .getColor(android.R.color.white)); decorView.removeView(decorChild); decorView.addView(slidingPaneLayout); // 為 SlidingPaneLayout 添加內容視圖 slidingPaneLayout.addView(decorChild, 1); } } protected boolean isSupportSwipeBack() { return true; } @Override public void onPanelSlide(View panel, float slideOffset) { } @Override public void onPanelOpened(View panel) { finish(); } @Override public void onPanelClosed(View panel) { } }
activity 透明style:
<resources xmlns:tools="http://schemas.android.com/tools"> <!-- 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="DIY.SlideClose.Transparent.Theme" parent="AppTheme"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@style/DIY.Animation.SlidingBack</item> <item name="android:actionBarStyle">@style/DIYActionBar.Custom</item> </style> <style name="DIYActionBar.Custom" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="displayOptions">showCustom</item> <item name="android:background">@android:color/transparent</item> <item name="background">@android:color/transparent</item> <item name="android:displayOptions" tools:ignore="NewApi">showCustom</item> <item name="android:height">?actionBarSize</item> </style> <style name="DIY.Animation.SlidingBack" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:activityOpenExitAnimation">@anim/slide_out_right</item> <item name="android:activityCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:activityCloseExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperOpenExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperCloseExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperIntraOpenEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperIntraOpenExitAnimation">@anim/slide_out_right</item> <item name="android:wallpaperIntraCloseEnterAnimation">@anim/slide_in_right</item> <item name="android:wallpaperIntraCloseExitAnimation">@anim/slide_out_right</item> </style> </resources>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。
本文實例講述了Android獲取手機屏幕大小的方法。分享給大家供大家參考,具體如下:這裡主要用了三個對象TextView ,Button ,以及DisplayMetric
下面給大家展示了AndroidHttpClient結構:public final classAndroidHttpClientextends Objectimplemen
百度了下,好像都沒找到想要的,或許是我百度錯了關鍵字吧。我這就介紹一種我現在剛學的方法。首先web端費給我們一個接口文檔。我這就接觸到兩塊內容:(1)通過接口傳遞單純的數
最近有很多人微信底部的變色卡片導航是怎麼做的,我在網上看了好幾個例子,都是效果接近,都存有一些差異,自己琢磨也做了一個,幾乎99%的還原,效果還不錯吧仔細觀察微信圖片,發