Android仿微信activity滑動(dòng)關(guān)閉功能
成都創(chuàng)新互聯(lián)專(zhuān)注于江西網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供江西營(yíng)銷(xiāo)型網(wǎng)站建設(shè),江西網(wǎng)站制作、江西網(wǎng)頁(yè)設(shè)計(jì)、江西網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開(kāi)發(fā)服務(wù),打造江西網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供江西網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
1.利用具體利用v4包下的slidingPaneLayout實(shí)現(xiàn)透明的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); // 通過(guò)反射改變mOverhangSize的值為0, // 這個(gè)mOverhangSize值為菜單到右邊屏幕的最短距離, // 默認(rèn)是32dp,現(xiàn)在給它改成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)); // 左側(cè)的透明視圖 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(); // 右側(cè)的內(nèi)容視圖 ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0); decorChild.setBackgroundColor(getResources() .getColor(android.R.color.white)); decorView.removeView(decorChild); decorView.addView(slidingPaneLayout); // 為 SlidingPaneLayout 添加內(nèi)容視圖 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:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。