安卓SlideMenu 仿QQ 主页侧滑菜单

先上图
这里写图片描述

这里写图片描述

仿qq 5.0

Activity 代码

package custom.community.com.mydemo;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;

import com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout;

import custom.community.com.mydemo.utils.CircleImageView;

public class MainActivity extends AppCompatActivity {
    private SlideSideMenuTransitionLayout mSlideSideMenu;
    private CircleImageView head_icon;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initWindow();
        // Grab the widget
        mSlideSideMenu = (SlideSideMenuTransitionLayout)findViewById(R.id.slide_side_menu);

        // Setup the toolbar
        head_icon = (CircleImageView) findViewById(R.id.base_toolbar);
        head_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mSlideSideMenu.toggle();
            }
        });

    }
    @Override
    public void onBackPressed() {
        if (mSlideSideMenu != null && mSlideSideMenu.closeSideMenu()) {
            // Closed the side menu, override the default back pressed behavior
            return;
        }
        super.onBackPressed();
    }
    //沉浸式状态栏
    private void initWindow(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }
}

xml布局

<?xml version="1.0" encoding="utf-8"?>
<com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/slide_side_menu"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/colorPrimary"
        android:padding="50dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:layout_marginTop="40dp"
            >

            <custom.community.com.mydemo.utils.CircleImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:src="@drawable/head_icon"
                app:border_width="0dp"
                />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
    android:text="小c欧巴"
    android:padding="12dp"
    />
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_marginTop="20dp"
            android:textColor="#ffffff"
            android:text="Item 1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 2"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 3"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 4"/>
    </LinearLayout>

    <com.lemonade.widgets.slidesidemenu.SlideSideMenuContentCardView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff">

            <!-- Optional: Tool Bar -->
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@color/colorPrimaryDark"
                android:paddingTop="26dp"
                android:paddingLeft="12dp"
                android:paddingRight="12dp"
                android:paddingBottom="12dp"
                >

                <custom.community.com.mydemo.utils.CircleImageView
                    android:id="@+id/base_toolbar"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:src="@drawable/head_icon"
                    app:border_width="0dp"
                    />

            </android.support.design.widget.AppBarLayout>

        </FrameLayout>
        <custom.community.com.mydemo.utils.CircleImageView
            android:layout_width="160dp"
            android:layout_height="160dp"
           android:layout_gravity="center"
            android:src="@drawable/head_icon"
            app:border_width="2dp"
            />
    </com.lemonade.widgets.slidesidemenu.SlideSideMenuContentCardView>
</com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout>

可以根据自己的需求更改

build.gradle

   compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:22.2.0'

项目链接:http://download.csdn.net/detail/summer_ck/9750620

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值