Android Menu 32种 菜单布局、源码、demo

DEMO下载列表

菜单类型 描述
AwesomeMenu ★5086 - 与Path的故事菜单具有相同外观的菜单
Context-Menu.Android ★2965 - 独特的动画内容菜单
DropDownMenu ★2010 - 多条件筛选菜单
FlyoutMenus ★821 - Android简易MD风格弹出菜单
TapBarMenu ★803 - Tap Bar菜单布局
CircleMenu ★723 - 具有设计感的菜单
SpinMenu ★656 - 轮播样式的Fragment菜单选择空间
DropDownMenu ★632 - 完整的筛选器解决方案
BlurredGridMenu ★470 - 酷炫网格菜单
ThumbnailMenu ★422 - 简单而精致的Fragment菜单控件
TopRightMenu ★349 - 仿手机QQ界面右上角的弹出菜单
CycleMenu ★251 - 圆形菜单
CircleProgressMenu ★108 - 带有进度效果的简单环形菜单
抽屉菜单类型 描述
MaterialDrawer ★7582 - 安卓抽屉效果实现方案
Side-Menu.Android ★3979 - 创意边侧菜单
FlowingDrawer ★1784 - 向右滑动流动抽屉效果
SlidingRootNav ★1589 - 仿DrawerLayout的ViewGroup
FantasySlide ★1084 - 单手势滑出侧边栏与选择菜单
Floating-Navigation-View ★806 - 浮动菜单显示锚导航视图
material-drawer ★538 - MD风格的自定义抽屉实现
SwipeMenuDemo ★533 - 侧滑菜单动画效果库
ArcNavigationView ★353 - 具有曲线边缘的NavigationView
SlideSideMenu ★116 - 滑动侧菜单的布局部件
PopupMenuView ★408 - iOS中弹框气泡菜单的控件
InfinityMenu ★110 - 实现手风琴样式菜单的Android库
FloatingMusicMenu ★252 - 用于音乐播放器的悬浮菜单按钮
CircleMenuView ★86 - 自定义圆形菜单
SlidMenu ★37 - 轮盘样式的Fragment菜单选择控件
SectorMenu ★150 - 炫酷的扇形菜单
浮动菜单类型 描述
BoomMenu ★5700+ 具有炸裂效果的菜单按钮
CircularFloatingActionMenu ★2700+ - 自定义圆形浮动动画菜单
TapBarMenu ★1000+ Tap Bar菜单布局

第一种 SpinMenu

轮盘样式的 Fragment 菜单选择控件。有没有很炫?

预览


目录

  • DEMO下载列表
  • 第一种 SpinMenu
    • 预览
    • 使用
    • 自定义配置
  • 第二种:ContextMenu
    • 使用:
  • 第三种 DropDownMenu
    • 预览
    • 特色
    • Gradle Dependency
    • 使用
  • 第五种 TapBar Menu
  • 简介
    • Install
    • Use

使用

导入 smlibrary module, 或者直接拷贝 com.hitomi.smlibrary 包下所有 java 文件到您的项目中

布局文件中:

    

        

    

如果您觉得背景太空洞,可以在 SpinMenu 中嵌套其它布局,来绘制您自己的背景

Activity 中:

spinMenu = (SpinMenu) findViewById(R.id.spin_menu);

// 设置页面标题
List hintStrList = new ArrayList<>();
hintStrList.add("热门信息");
hintStrList.add("实时新闻");
hintStrList.add("我的论坛");
hintStrList.add("我的信息");
hintStrList.add("走走看看");
hintStrList.add("阅读空间");
hintStrList.add("听听唱唱");
hintStrList.add("系统设置");

spinMenu.setHintTextStrList(hintStrList);
spinMenu.setHintTextColor(Color.parseColor("#FFFFFF"));
spinMenu.setHintTextSize(14);

// 设置启动手势开启菜单
spinMenu.setEnableGesture(true);

// 设置页面适配器
final List fragmentList = new ArrayList<>();
fragmentList.add(Fragment1.newInstance());
fragmentList.add(Fragment2.newInstance());
fragmentList.add(Fragment3.newInstance());
fragmentList.add(Fragment4.newInstance());
fragmentList.add(Fragment5.newInstance());
fragmentList.add(Fragment6.newInstance());
fragmentList.add(Fragment7.newInstance());
fragmentList.add(Fragment8.newInstance());
FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }
};
spinMenu.setFragmentAdapter(fragmentPagerAdapter);

// 设置菜单状态改变时的监听器
spinMenu.setOnSpinMenuStateChangeListener(new OnSpinMenuStateChangeListener() {
    @Override
    public void onMenuOpened() {
        Toast.makeText(MainActivity.this, "SpinMenu opened", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onMenuClosed() {
        Toast.makeText(MainActivity.this, "SpinMenu closed", Toast.LENGTH_SHORT).show();
    }
});

自定义配置


支持页面缩放大小自定义,建议取值在3.0到5.0之间


支持页面标题文字颜色自定义


第二种:ContextMenu

You can easily add awesome animated context menu to your app.

Check this project on dribbble

Check this project on Behance

使用:

For a working implementation, have a look at the appmodule

  • Clone repository and add sources into your project or use Gradle:

Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Add the dependency

	dependencies {
	        implementation 'com.github.Yalantis:Context-Menu.Android:1.1.4'
	}
  • Create list of MenuObject, which consists of icon or icon and description.
    You can use any drawable, resource, bitmap, color as image:
    menuObject.drawable = ...
    menuObject.setResourceValue(...)
    menuObject.setBitmapValue(...)
    menuObject.setColorValue(...)

You can set image ScaleType:

    menuObject.scaleType = ScaleType.FIT_XY

You can use any resource, drawable, color as background:

    menuObject.setBgResourceValue(...)
    menuObject.setBgDrawable(...)
    menuObject.setBgColorValue(...)

Now You can easily add text appearance style for menu titles:

	In your project styles create style for text appearance
	(For better visual effect extend it from TextView.DefaultStyle):
	
	

	And set it's id to your MenuObject :	
    
        val bitmapDrawable = BitmapDrawable(
                resources,
                BitmapFactory.decodeResource(resources, R.drawable.icn_3)
        )

        val menuObject = MenuObject("Add to friends").apply {
            drawable = bitmapDrawable
            menuTextAppearanceStyle = R.style.TextViewStyle
        }

You can use any color as text color:

    menuObject.textColor = ...

You can set any color as divider color:

    menuObject.dividerColor = ...

Example:

    val close = MenuObject().apply { setResourceValue(R.drawable.icn_close) }

    val send = MenuObject("Send message").apply { setResourceValue(R.drawable.icn_1) }
    
    val addFriend = MenuObject("Add to friends").apply {
            drawable = BitmapDrawable(
                    resources,
                    BitmapFactory.decodeResource(resources, R.drawable.icn_3)
            )
    }

    val menuObjects = mutableListOf().apply {
            add(close)
            add(send)
            add(addFriend)
    }
  • Create newInstance of ContextMenuDialogFragment, which received MenuParams object.
    val menuParams = MenuParams(
    	actionBarSize = resources.getDimension(R.dimen.tool_bar_height).toInt(),
    	menuObjects = getMenuObjects(),
    	isClosableOutside = false
    	// set other settings to meet your needs
    )
    
    // If you want to change the side you need to add 'gravity' parameter,
    // by default it is MenuGravity.END.
    
    // For example:
    
    val menuParams = MenuParams(
    	actionBarSize = resources.getDimension(R.dimen.tool_bar_height).toInt(),
    	menuObjects = getMenuObjects(),
    	isClosableOutside = false,
    	gravity = MenuGravity.START
    )
    
    val contextMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams)
  • Set menu with button, which will open ContextMenuDialogFragment.
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        item?.let {
            when (it.itemId) {
                R.id.context_menu -> {
                    showContextMenuDialogFragment()
                }
            }
        }

        return super.onOptionsItemSelected(item)
    }
  • Add menu item listeners.
    contextMenuDialogFragment = menuItemClickListener = { view, position ->
    	// do something here
    }
	    
    contextMenuDialogFragment = menuItemLongClickListener = { view, position ->
    	// do something here
    }

第三种 DropDownMenu

预览

Download APK

或者扫描二维码

Android Menu 32种 菜单布局、源码、demo_第1张图片 ## 简介 一个实用的多条件筛选菜单,在很多App上都能看到这个效果,如美团,爱奇艺电影票等

特色

  • 支持多级菜单
  • 你可以完全自定义你的菜单样式,我这里只是封装了一些实用的方法,Tab的切换效果,菜单显示隐藏效果等
  • 并非用popupWindow实现,无卡顿

Gradle Dependency

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    compile 'com.github.dongjunkun:DropDownMenu:1.0.4'
}

使用

添加DropDownMenu 到你的布局文件,如下


我们只需要在java代码中调用下面的代码

 //tabs 所有标题,popupViews  所有菜单,contentView 内容
mDropDownMenu.setDropDownMenu(tabs, popupViews, contentView);

如果你要了解更多,可以直接看源码 Example

建议拷贝代码到项目中使用,拷贝DropDownMenu.java 以及res下的所有文件即可

第五种 TapBar Menu

简介

Simple library that helps creating a “Tap Bar” menu layout.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Sk66MwEi-1622197989840)(http://i.giphy.com/ZRCzrySXUaMwM.gif “Demo 1”)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-n3OoMnjK-1622197989843)(http://i.giphy.com/zIBFfp4iLlGAo.gif “Demo 2”)]

Demo 1: https://youtu.be/DjY0cTWWtao

Demo 2: https://youtu.be/dWuPMN6WTOY

Install

Since version 1.0.6 this library is being distributed via JitPack

Step 1:
Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2:
Add the dependency:

dependencies {
	implementation 'com.github.michaldrabik:TapBarMenu:1.0.6'
}

For versions 1.0.5 and older:

Add the dependency to your build.gradle:

dependencies {
    compile 'com.github.michaldrabik:tapbarmenu:1.0.5'
}

Use

Check sample project for a full example.

TapBarMenu is an extension of a LinearLayout so you can simply put it in your XML. For example:

<com.michaldrabik.tapbarmenulib.TapBarMenu
  android:id="@+id/tapBarMenu"
  android:layout_width="match_parent"
  android:layout_height="56dp"
  android:layout_gravity="bottom"
  android:layout_marginBottom="24dp"
  >
  
    <ImageView
      android:id="@+id/item1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:paddingTop="10dp"
      android:paddingBottom="10dp"
      android:src="@drawable/ic_thumb_up"
      />
  
    <Space
      android:layout_width="56dp"
      android:layout_height="match_parent"
      />
  
    <ImageView
      android:id="@+id/item2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:paddingTop="10dp"
      android:paddingBottom="10dp"
      android:src="@drawable/ic_thumb_down"
      />
   
com.michaldrabik.tapbarmenulib.TapBarMenu>

This will create a menu with 2 icons in the bottom of the screen.

Then, in your code, call open(), close() or toggle() to open/close the menu:

tapBarMenu.setOnClickListener(new View.OnClickListener() {
  @Override public void onClick(View v) {
    tapBarMenu.toggle();
  }
});

Note: TapBarMenu will always expand to its parent width. You can choose between 2 anchors bottom or top - see attributes below.

你可能感兴趣的:(Android,android,app,viewpager,android,studio,java)