Android 下拉框第三方控件 NiceSpinner

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 文件中加入:

<org.angmarch.views.NiceSpinner
    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"/>
nametypeinfo
arrowTintcolorsets the color on the drop-down arrow
hideArrowbooleanset whether show or hide the drop-down arrow
arrowDrawablereferenceset the drawable of the drop-down arrow
textTintcolorset the text color
dropDownListPaddingBottomdimensionset the bottom padding of the drop-down list
backgroundSelectorintegerset the background selector for the drop-down list rows

在 MainActivity.java 中加入:

private NiceSpinner niceSpinner;
List<String> spinnerData = 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"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- view背景色 -->
    <solid android:color="#52a2e2" />
    <!-- 边框颜色 宽度 -->
    <stroke
        android:width="1dip"
        android:color="#52a2e2" />
    <!-- 边框圆角 -->
    <corners
        android:bottomRightRadius="6dp"
        android:topRightRadius="6dp"
        android:bottomLeftRadius="6dp"
        android:topLeftRadius="6dp"/>
</shape>


在 nice-spinner-master/src/main/java/NiceSpinner 目录下可以修改属性


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值