Android 下拉框第三方控件 NiceSpinner
16lz
2021-01-23
NiceSpinner 是 Android 端的一款第三方控件,自带箭头动画效果
GitHub地址
效果图如下:
目录
1. 导入模块
2. 代码测试
1. 导入模块
在 Github 下载并导入模块
或者在 build.gradle 中修改:
allprojects { repositories { ... maven { url "https://jitpack.io" } }}dependencies { compile 'com.github.arcadefire:nice-spinner:1.3.1'}
建议导入模块,可以修改。
2. 代码测试
在 activity_main.xml 文件中加入:
android:id="@+id/nice_spinner" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" app:arrowTint="@color/light_gray" app:textTint="@color/myBlack" app:dropDownListPaddingBottom="60dp" android:layout_marginEnd="12dp" android:layout_marginRight="12dp"/>
name | type | info |
---|---|---|
arrowTint | color | sets the color on the drop-down arrow |
hideArrow | boolean | set whether show or hide the drop-down arrow |
arrowDrawable | reference | set the drawable of the drop-down arrow |
textTint | color | set the text color |
dropDownListPaddingBottom | dimension | set the bottom padding of the drop-down list |
backgroundSelector | integer | set the background selector for the drop-down list rows |
在 MainActivity.java 中加入:
private NiceSpinner niceSpinner;ListspinnerData = new LinkedList<>(Arrays.asList("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"));
niceSpinner = findViewById(R.id.nice_spinner);
niceSpinner.attachDataSource(spinnerData);niceSpinner.setBackgroundResource(R.drawable.textview_round_border);niceSpinner.setTextColor(Color.WHITE);niceSpinner.setTextSize(13);
niceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { } @Override public void onNothingSelected(AdapterView<?> parent) {}});
textview_round_border.xml (设置圆角等属性,放在 drawable 目录下)
<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" > android:color="#52a2e2" /> android:width="1dip" android:color="#52a2e2" /> android:bottomRightRadius="6dp" android:topRightRadius="6dp" android:bottomLeftRadius="6dp" android:topLeftRadius="6dp"/>
在 nice-spinner-master/src/main/java/NiceSpinner 目录下可以修改属性
更多相关文章
- android中的EditView控件
- Android 中的各种控件
- Android 如何通过menu id来得到menu item 控件
- android 各类开源项目整理 包括 个性化控件 工具库 完整优秀项目
- 情况控件Android layout_weight用法图解
- Android 基于4G模块 GPS定位
- Android 自定义日期控件,包含月控件
- Android Spinner控件之键值对用法