Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.fg2q1q3q:dropdownmenu:1.1.1'
}
dependencies {
implementation("com.github.fg2q1q3q:dropdownmenu:1.1.1")
}
<dependency>
<groupId>com.github.fg2q1q3q</groupId>
<artifactId>dropdownmenu</artifactId>
<version>1.1.1</version>
</dependency>
libraryDependencies += "com.github.fg2q1q3q" % "dropdownmenu" % "1.1.1"
:dependencies [[com.github.fg2q1q3q/dropdownmenu "1.1.1"]]
本例是在DropDownMenu基础上改进而来 ####1.1.1修改:
app:ddneedSetSlectedColor="true"
####相比而言增加de特性:
####以下为原始特性
##ScreenShot <img src="https://github.com/fg2q1q3q/DropDownMenu/blob/master/art/d.gif?raw=true"/>
##Gradle 在project 中build.gradle下增加(已有跳过)
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
在app module中增加
dependencies {
compile 'com.github.fg2q1q3q:DropDownMenu:1.1.1'
}
使用相关核心源码及参数说明:
//一共包含四种类型:三种默认类型和自定义
public static final int TYPE_LIST_CITY = 1;
public static final int TYPE_LIST_SIMPLE = 2;
public static final int TYPE_GRID = 3;
public static final int TYPE_CUSTOM = 4;
/**
* @param tabTexts tab标签字符串集合
* @param contentView 主页面view
* @param viewDatas 为数据源hashmap
* KEY对应TYPE(上文常量)
* VALUE对应数据源(非TYPE_CUSTOM-->string[]或TYPE_CUSTOM-->customView)
*/
public void setDropDownMenu(@NonNull List<String> tabTexts,
@NonNull List<HashMap<String,Object>> viewDatas,@NonNull View contentView){
}
###使用教程 添加DropDownMenu 到你的布局文件,如下
<com.zxl.library.DropDownMenu
android:id="@+id/dropDownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ddmenuTextSize="13sp" //tab字体大小
app:ddtextUnselectedColor="@color/drop_down_unselected" //tab未选中颜色
app:ddtextSelectedColor="@color/drop_down_selected" //tab选中颜色
app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon" //tab选中状态图标
app:ddmenuUnselectedIcon="@mipmap/drop_down_unselected_icon"//tab未选中状态图标
app:ddmaskColor="@color/mask_color" //遮罩颜色,一般是半透明
app:ddmenuBackgroundColor="@color/white" //tab 背景颜色
app:ddmenuMaxHeight="280dp"//筛选菜单最大高度,默认为wrap
app:ddneedSetSlectedColor="true"//设置选中option后tab是否改变颜色
...
/>
java代码中设置如下:
View contentView = getLayoutInflater().inflate(R.layout.contentview, null);
mDropDownMenu.setDropDownMenu(Arrays.asList(headers), initViewData(), contentView);
//该监听回调只监听默认类型,如果是自定义view请自行设置监听,参照demo
mDropDownMenu.addMenuSelectListener(new DropDownMenu.OnDefultMenuSelectListener() {
@Override
public void onSelectDefaultMenu(int index, int pos,String clickstr) {
//index:点击的tab索引,pos:单项菜单中点击的位置索引,clickstr:点击位置的字符串
Toast.makeText(getBaseContext(),clickstr,Toast.LENGTH_SHORT).show();
}
});
详情可参考demo,点此下载或扫描二维码
##联系我
如有疑问请提issue或<img src="http://pub.idqqimg.com/wpa/images/group.png"/>