首页 » Andorid » 临时分类 » 正文

android-dropdown-menu

android-dropdown-menu

An dropdown menu for android, you can attach your own listView(s) with this.

文档

DropdownMenu

Demo

DropdownMenu demo

Usage

You can use this to make several(as you want) listViews act like dropdown menu, the 'weight' of titles' width is adjustable. It will not intercept touch events when it get back.

Use this view in xml:

Then find this view and setup():

    mDropdownView = (DropdownView) findViewById(R.id.dropdown_view);
    mDropdownView.setup(simpleListView1, simpleListView2);
    mDropdownView.setOnDropdownItemClickListener(new DropdownView.OnDropdownItemClickListener() {
        @Override
        public void onItemClick(View v, int whichList, int position) {
            mDropdownView.setTitleText(whichList, whichList + "-" + position);
        }
    });
    //enable functions you need. default value is true
    mDropdownView.enableDimBackground(true);
    mDropdownView.enableAutoBackOnItemClick(true);

Or you can just new DropdownView in code:

    DropdownView dropdownView = new DropdownView(this);
    dropdownView.setup(3, titles_arr, simpleListView1, simpleListView2, simpleListView3);
    root.addView(dropdownView);

Remember to provide listViews, and register onDropdownItemClickListener.

Include

You can use gradle to grab it from maven central:

compile 'com.opticalix.dropdownmenu:dropdown-lib:1.0.1'

Config

You may need to modify part of the DropdownView, methods like 'setTitleBackgroundColor' are available.

  • optional

    • titleTextColor
    • titleTextSize
    • titleBackground
    • titlePadding
    • arrowDrawable
    • arrowDrawablePadding
    • listViewHeight
    • duration
    • enableDimBackground
    • enableAutoBackOnItemClick
  • necessary

    • listCount
    • listViews
    • titleText

Notice

If you find dropdownView is cover by other views in LOLLIPOP, you can:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mDropdownView.setZ(100);//larger than others
    }
下载 (0)

发表评论